All pastes #937338 Raw Edit

Miscellany

public php v1 · immutable
·published 2008-03-10 23:29 UTC
rendered paste body
<?phppublic function resample ($filename) {        $thumbpath = implode("/thumbs/",explode("/",$filename));        if(file_exists($thumbpath))            return false;                if(!is_dir($this->page . "/thumbs/"))            #mkdir("hej_lolerkon/thumbs",0777);            mkdir($this->page . "/thumbs/",0777);                $im = @imagecreatetruecolor(WIDTH, HEIGHT)              or die("trasigt!");        list($width, $height) = getimagesize($filename);        $w = $width/WIDTH;        $h = $height/HEIGHT;        if($w==$h) { // The AR is correct            $nwidth = WIDTH;            $nheight = HEIGHT;        }        elseif($w>$h) { // It's too wide!            $nwidth = $width/$h;            $nheight = $height/$h;        }        elseif($w<$h) { // It's too tall!            $nwidth = $width/$w;            $nheight = $height/$w;        }                #echo $nwidth . "x" . $nheight;        $newimage = imagecreatetruecolor(WIDTH, HEIGHT);        $ext = strtolower(pathinfo($filename,PATHINFO_EXTENSION));        switch($ext) {            case "jpeg":            case "jpg":                $image = imagecreatefromjpeg($filename);            break;            case "gif":                $image = imagecreatefromgif($filename);            break;            case "png":                $image = imagecreatefrompng($filename);            break;        }