Creates a thumbnail from an existing image. $filename is the original filename, while $tmpname is the actual filesystem name (for example, the temporary filename used in a PHP upload). Returns an image resource which you can then output to the browser, or save to a file using imagejpg(), imagepng(), etc.
function resize_image($filename, $tmpname, $xmax, $ymax) { if($ext == "jpg" || $ext == "jpeg") $im = imagecreatefromjpeg($tmpname); elseif($ext == "png") $im = imagecreatefrompng($tmpname); elseif($ext == "gif") $im = imagecreatefromgif($tmpname); $x = imagesx($im); $y = imagesy($im); if($x <= $xmax && $y <= $ymax) return $im; if($x >= $y) { $newx = $xmax; $newy = $newx * $y / $x; } else { $newy = $ymax; $newx = $x / $y * $newy; } $im2 = imagecreatetruecolor($newx, $newy); return $im2; }
Comments
Subscribe to comments
You need to login to post a comment.

I can't not to use after return value . Example : I want to Link this image to resize, I can't. I want to print images tree line, I can't.
Please tell me.
Best regards,
Thon, Thank you.
This is awesome, this is just what I have been looking for, thank you.
You should use imagecopyresampled() instead of imagecopyresized(). You'll have much soften images. And arguments are exactly the same.
A nice OOP-PHP5-Class for crating Thumbnails: https://github.com/SteffenHagdorn/Pixlie