gerkintrigg Posted August 8, 2007 Share Posted August 8, 2007 What's the easiest way to rescale an image to specific dimensions (but maintain aspect ratios) and save the output to a thumbnail folder? Is there a versatile free script out there somewhere? I've been searching but have only found ones that do the re-scaling on the fly. Thanks Link to comment https://forums.phpfreaks.com/topic/63872-solved-resize-an-image/ Share on other sites More sharing options...
mrjcfreak Posted August 8, 2007 Share Posted August 8, 2007 This one only works for jpgs... <? $img = $_REQUEST['img']; //$img must be in same dir as script... if not hoojah is needed, not too complicated though... $sizes = @ getimagesize($img); //here sizes[0] means WIDTH is tested- if smaller than 480 just serve up original img. //if you want to measure by height, use sizes[1]... if a mix of both, then just write the corresponding of gates if($sizes[0]<=480 || $sizes == false) { header("Location: $img"); exit; } //Resize height to match the new width $height = $sizes[1]*480/$sizes[0]; header("Content-type: image/jpeg"); $thumb = imagecreatetruecolor(480, $height); $source = imagecreatefromjpeg($img); imagecopyresampled($thumb, $source, 0, 0, 0, 0, 480, $height, $sizes[0], $sizes[1]); imagejpeg($thumb); imagedestroy($thumb); imagedestroy($source); ?> This outputs the image to browser, you can also output to image by using imagejpeg($thumb, "FILENAME") I wrote that a while back for a gallery. Also look up www.php.net/gd2 Link to comment https://forums.phpfreaks.com/topic/63872-solved-resize-an-image/#findComment-318360 Share on other sites More sharing options...
jitesh Posted August 8, 2007 Share Posted August 8, 2007 http://www.phpfreaks.com/forums/index.php/topic,141077.msg600776.html#msg600776 Link to comment https://forums.phpfreaks.com/topic/63872-solved-resize-an-image/#findComment-318377 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.