D. Alvarado wrote:
Hello,
Can anyone recommend a good image scaling program for PHP 4. What
I'm really looking for is just a function that takes an image file and
a width to which to scale the image and outputs the scaled image.
$src and $tgt are absolute paths to the source file and new image.
$size will be the maximum dimension (either width or height) of the
reuslting rescaled image.
If size isnt given, it will be 150 pixels.
function createthumb ($src,$tgt,$siz e=150) {
// create new thumbnail !
$src_img = imagecreatefrom jpeg($src);
if ($src_img) {
// calc portrait or landscape
if (imagesx($src_i mg) < imagesy($src_im g))
$scale = imagesy($src_im g) /$size;
else $scale = imagesx($src_im g) /$size;
// calc thumbnail dimensions
$new_w = round(imagesx($ src_img)/$scale);
$new_h = round(imagesy($ src_img)/$scale);
// create empty image of correct size & copy/resize image into it
$dst_img = imagecreatetrue color($new_w,$n ew_h);
imagecopyresize d($dst_img,$src _img,0,0,0,0,
$new_w,$new_h,
imagesx($src_im g),imagesy($src _img));
imagedestroy($s rc_img);
// save thumbnail to file
imagejpeg($dst_ img, $tgt);
imagedestroy($d st_img);
}
else print "<div class=error>fai led to open $src</div>";
}