anita999 Posted April 18, 2007 Share Posted April 18, 2007 I have a list of items with their images displayed in a column. I would like to resize the images into small fixed size images. Is there a way to do this efficiently since I have about 10 items per page. I also do not want resized images to be produced in the file directory? Any suggestions on how to do this efficiently would be appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted April 18, 2007 Share Posted April 18, 2007 Well to do it efficiently you would want to save the thumbnails in a separate folder so that you wont have to dynamically resize every image on the page every time the image is requested. As for actually doing the resizing, google is a great place to find tutorials... http://www.google.com/search?q=resizing+an+image+in+php&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a Quote Link to comment Share on other sites More sharing options...
Maverickb7 Posted April 18, 2007 Share Posted April 18, 2007 This should resize your image fairly easy. I'm sure you could come up with something better if you modified it a bit. You could set it up as a function so it'll be easy to use. <?php // The file you are resizing $file = 'yourfile.jpg'; //This will set our output to 45% of the original size $size = 0.45; // This sets it to a .jpg, but you can change this to png or gif header('Content-type: image/jpeg'); // Setting the resize parameters list($width, $height) = getimagesize($file); $modwidth = $width * $size; $modheight = $height * $size; // Resizing the Image $tn = imagecreatetruecolor($modwidth, $modheight); $image = imagecreatefromjpeg($file); imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height); // Outputting a .jpg, you can make this gif or png if you want //notice we set the quality (third value) to 100 imagejpeg($tn, null, 100); ?> Quote Link to comment Share on other sites More sharing options...
anita999 Posted April 18, 2007 Author Share Posted April 18, 2007 Thank you. I tried the sample code but when the image is printed to the screen, it prints out symbols instead of the image. I tried reading in a gif file and changed all references to the code from jpeg to gif. But that didn't work either. Quote Link to comment Share on other sites More sharing options...
Maverickb7 Posted April 18, 2007 Share Posted April 18, 2007 I think your using the code wrong. Create a file called thumbnail.php and place this code in. Now simply use thumbnail.php like it was an image and call it like: <img src="http://www.yoursite.com/thumbnail.php"> this should work for you as long as you have an image called yourfile.jpg in the same directory. You could use $_GET to specific which image you wanna thumbnail as well, rather then naming a file within thumbnail.php. Hope that helps! Quote Link to comment 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.