View Single Post
Old 06-03-2004, 10:01 PM   #3 (permalink)
Trueliar
Junior Member
 
Join Date: 06-03-04
Posts: 18
iTrader: 0 / 0%
Latest Blog:
None

Trueliar is liked by many
Re: PHP Image Resize Issue

Quote:
Originally Posted by ATLien
[code:1:a430e8278f]function resize($fname, $output, $max_width, $max_height, $quality = 75) {

getimagesize($fname);
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}

$im = imagecreatefromjpeg($fname);
$dst = imagecreatetruecolor($tn_width,$tn_height);
imagecopyresampled($dst, $im, 0, 0, 0, 0,$tn_width,$tn_height,$width,$height);
imagejpeg($dst, $output, $quality);
imagedestroy($im);
imagedestroy($dst);
}
[/code:1:a430e8278f]

Ok, someone gave me the above code to create a thumb. I want to know what varible I would use to echo the path to the image created in the function. Can anyone help me?
Easy thing .....

just correct the code here at the 2nd line in the function

->> getimagesize($fname);

getimagesize returns an array that is used in the rest of the function

correct ->> $size = getimagesize($fname);

it's just a mistyping error.


the output file is the 2nd argument

for ex should be used as follow:
resize("/mypath/image1.jpg","/mypath/thumbs/image1-thumb.jpg", 80,80,100);


I suggest to add some code for the proportions if you intend to have a nice looking thumb

cy
Trueliar is offline   Reply With Quote