ukscotth Posted July 16, 2009 Share Posted July 16, 2009 Hi, I have this script for creating thumbnails which works fine but can someone please show me how to modify it so instead of it changeing the width every time it changes either the width or height, whichever one is bigger. So if i set it to say 150, neither the height or width will ever be bigger than 150. Also so it doesnt increase the size if both the width and height are already lower than 150. Hope that makes sense and i hope someone can help <?php function makeThumbs( $pathToImages, $pathToThumbs, $thumbWidth ) { $dir = opendir($pathToImages); while (false !== ($fname = readdir($dir))) { $info = pathinfo($pathToImages . $fname); if (strtolower($info['extension']) == 'jpg') { echo "Creating thumbnail for $fname <br />"; $img = imagecreatefromjpeg($pathToImages . $fname); $width = imagesx($img); $height = imagesy($img); $new_width = $thumbWidth; $new_height = floor($height * ($thumbWidth / $width)); $tmp_img = imagecreatetruecolor($new_width, $new_height); imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}"); } } closedir($dir); } makeThumbs("pictures/","thumbs/",150); ?> Quote Link to comment https://forums.phpfreaks.com/topic/166210-creating-thumbs-script-slight-change-needed/ Share on other sites More sharing options...
ignace Posted July 16, 2009 Share Posted July 16, 2009 http://mediumexposure.com/techblog/smart-image-resizing-while-preserving-transparency-php-and-gd-library or http://www.imagemagick.org/script/index.php Quote Link to comment https://forums.phpfreaks.com/topic/166210-creating-thumbs-script-slight-change-needed/#findComment-876466 Share on other sites More sharing options...
ukscotth Posted July 16, 2009 Author Share Posted July 16, 2009 thnx, both of those look pretty complicated and not sure if u can use them for a folder full of pictures is there not a simple modification i can make to the script i posted ? thnx Scott Quote Link to comment https://forums.phpfreaks.com/topic/166210-creating-thumbs-script-slight-change-needed/#findComment-876517 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.