Arty Ziff Posted July 29, 2008 Share Posted July 29, 2008 I use something like this to resize dynamically images. Is there a way to wrap this in a function and class that when called returns the image object? <? $src_img = imagecreatefromjpeg('./path/to/image.jpg'); $srcsize = getimagesize('./path/to/image.jpg'); $dest_x = 200; $dest_y = (200 / $srcsize[0]) * $srcsize[1]; $dst_img = imagecreatetruecolor($dest_x, $dest_y); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_x, $dest_y, $srcsize[0], $srcsize[1]); header("content-type: image/jpeg"); imagejpeg($dst_img); imagedestroy($src_img); imagedestroy($dst_img); ?> For exacmple, right now I could use it to dynamically resize images by having it inline in the HTML: <img src="./image_script.php?img=image_name.jpg"> But if it could be wrapped in a class / function, it could be done without exposing the script to possible exploitation maybe... I'd like to avoid resizing the image and dumping it in a temp directory. That could get huge. Link to comment https://forums.phpfreaks.com/topic/117120-dynamically-resizing-images-on-the-fly/ Share on other sites More sharing options...
ignace Posted July 29, 2008 Share Posted July 29, 2008 take a look at: http://mediumexposure.com/techblog/smart-image-resizing-while-preserving-transparency-php-and-gd-library also make sure your memory_limit is high enough to resize big images Link to comment https://forums.phpfreaks.com/topic/117120-dynamically-resizing-images-on-the-fly/#findComment-602427 Share on other sites More sharing options...
nashruddin Posted July 29, 2008 Share Posted July 29, 2008 Here's my class to create image's thumbnail on-the-fly: http://www.nashruddin.com/create-image-thumbnail-on-the-fly.html Link to comment https://forums.phpfreaks.com/topic/117120-dynamically-resizing-images-on-the-fly/#findComment-602673 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.