All pastes #262429 Raw Edit

me

public php v1 · immutable
#262429 ·published 2006-11-30 14:40 UTC
rendered paste body
function createthumb($file_src,$ext, $file_dest,$new_w=350,$new_h=300) {        if (in_array($ext, array( "jpg", "jpeg"))){                $src_img=@imagecreatefromjpeg($file_src);        } elseif ( in_array($ext, "png")) {                $src_img=@imagecreatefrompng($file_src);        } else {                return(false);        }        if (!$src_img) {                return(false);        }        $old_x=imageSX($src_img);        $old_y=imageSY($src_img);        if ($old_x > $old_y) {                $thumb_w=$new_w;                $thumb_h=($old_y*$new_w)/$old_x;        }        if ($old_x < $old_y) {                $thumb_w=($old_x*$new_h)/$old_y;                $thumb_h=$new_h;        }        if ($old_x == $old_y) {                $thumb_w=$new_w;                $thumb_h=$new_w;        }        $dst_img=@ImageCreateTrueColor($thumb_w,$thumb_h);        if (!imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y)) return(false);        if ($ext == "png") {                imagepng($dst_img,$file_dest);        } else {                imagejpeg($dst_img,$file_dest);        }        imagedestroy($dst_img);        imagedestroy($src_img);        return(true);}