jarvis Posted November 12, 2009 Share Posted November 12, 2009 Hi all, I've got the following script which nicely creates my thumbnail at 120px high or wide. Rather than copy the original size image as well, I'd like the original resized to 800x600 I cannot see the best way to do this, so any help is much appreciated! Here's my code. function saveThumb($gal,$fn) { define("MAX_XY", 120); // maximum width or height of thumbnail image $fpath = "categories/$gal/$fn"; $info = GetImageSize("$fpath"); // do we need to resize image? if ($info[0] > MAX_XY || $info[1] > MAX_XY) { // is image landscape? if ($info[0] >= $info[1]) { $width = MAX_XY; $height = $info[1]*MAX_XY/$info[0]; // or portrait? } else { $height = MAX_XY; $width = $info[0]*MAX_XY/$info[1]; } } else { // use original dimensions $width = $info[0]; $height = $info[1]; } // create new thumbnail image $im = ImageCreateTrueColor($width, $height); $im_big = ""; // default is no image switch ($info[2]) { case 1 : if (ImageTypes() & IMG_GIF) // test for GIF support $im_big = ImageCreateFromGIF("$fpath"); break; case 2 : if (ImageTypes() & IMG_JPG) // test for JPEG support $im_big = ImageCreateFromJPEG("$fpath"); break; case 3 : if (ImageTypes() & IMG_PNG) // test for PNG support $im_big = ImageCreateFromPNG("$fpath"); break; case 4 : if (ImageTypes() & IMG_BMP) // test for BMP support $im_big = ImageCreateFromBMP("$fpath"); break; } if ($im_big) { /* resize original image into thumbnail - see PHP Manual for details on * the arguements ImageCopyResized takes */ ImageCopyResized($im,$im_big,0,0,0,0,$width,$height,$info[0],$info[1]); } else { // couldn't load original image, so generate 'no thumbnail' image instead $width = 120; $height = 120; $im = ImageCreate($width, $height); // create a blank image $bgc = ImageColorAllocate($im, 0, 0, 0); // background color = black $tc = ImageColorAllocate($im, 255, 255, 255); // text color = white ImageFilledRectangle($im, 0, 0, $width, $height, $bgc); // draw rectangle ImageString($im, 3, 9, 36, "No thumbnail", $tc); // add text ImageString($im, 3, 17, 48, "available", $tc); } /* save our image in thumb directory - if the second argument is left out, * the image gets sent to the browser, as in thumbnail.php */ ImageJPEG($im, "categories/".$gal."/t_".$fn); // clean up our working images ImageDestroy($im_big); ImageDestroy($im); } Thanks in advanced! Quote Link to comment https://forums.phpfreaks.com/topic/181216-image-resize-script-issue/ Share on other sites More sharing options...
darkvengance Posted November 12, 2009 Share Posted November 12, 2009 Hello, try out this script, it's one I made a while back and this script compresses images to a size which is specified by you, and either saves them or prints them to the browser. http://www.coderprofile.com/coder/Darkvengance/source-codes/view?id=85 Quote Link to comment https://forums.phpfreaks.com/topic/181216-image-resize-script-issue/#findComment-956011 Share on other sites More sharing options...
jarvis Posted November 12, 2009 Author Share Posted November 12, 2009 Thanks darkvengance that's very kind! Although it doesn't check for image types and looks like it doesn't generate 2 images. I need the thumb & the original but need to resize both. Maybe even copy the original too (just incase!) Thanks Quote Link to comment https://forums.phpfreaks.com/topic/181216-image-resize-script-issue/#findComment-956016 Share on other sites More sharing options...
darkvengance Posted November 12, 2009 Share Posted November 12, 2009 Oh...yeh you're right it doesn't check for image types...but do you want the thumb to be a specific type? With this script you can just use it to create the thumbnail with whatever dimensions you want...just for $img use the originall image, and for $path enter the path you want to store the thumbnail in and it will create/save it for you. But other then that here are a few more that I've found for ya: http://www.mightystuff.net/php_thumbnail_script http://phpthumb.sourceforge.net/ Quote Link to comment https://forums.phpfreaks.com/topic/181216-image-resize-script-issue/#findComment-956018 Share on other sites More sharing options...
jarvis Posted November 12, 2009 Author Share Posted November 12, 2009 thanks again darkvengance, i'll go take a look! Cheers Quote Link to comment https://forums.phpfreaks.com/topic/181216-image-resize-script-issue/#findComment-956026 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.