SharkBait Posted September 3, 2006 Share Posted September 3, 2006 Hi, I am looking at learning to play with the GD by incorporating it into my little site.I want to be able to upload images and have the GD create a thumbnail and store it in a thumbnail directory and have the original image stored in another directory. These entries will also be put into a database.What should I be looking into? I can't remember that URL for the GD site, but I am sure someone else can.When I display an image to someone on my site, can I have the GD put a border around the image as well?Or is it imagemagik that I should be looking into? Link to comment https://forums.phpfreaks.com/topic/19593-best-way-image-to-thumbnail/ Share on other sites More sharing options...
ronverdonk Posted September 3, 2006 Share Posted September 3, 2006 For more documentation on using GD see[url=http://nl2.php.net/gd]http://nl2.php.net/gd[/url][url=http://www.phpbuilder.com/columns/index.php3?cat=2&subcat=17]http://www.phpbuilder.com/columns/index.php3?cat=2&subcat=17[/url]Ronald 8) Link to comment https://forums.phpfreaks.com/topic/19593-best-way-image-to-thumbnail/#findComment-85245 Share on other sites More sharing options...
SharkBait Posted September 4, 2006 Author Share Posted September 4, 2006 Thoughs are some decent tutorials, thanksIs it possible to create the thumbail on the fly? What I mean is when a page is loaded and images are to be shown that it shows a tempoary thumbnail instead of the full image? Or is it best to create the thumbnail upon uploading of the image and just store it? Link to comment https://forums.phpfreaks.com/topic/19593-best-way-image-to-thumbnail/#findComment-85781 Share on other sites More sharing options...
GingerRobot Posted September 4, 2006 Share Posted September 4, 2006 I would think you would be better creating the thumbnail when the image is uploaded. That way you are only doing this piece of processing once, rather than doing it every time someone views the image. Link to comment https://forums.phpfreaks.com/topic/19593-best-way-image-to-thumbnail/#findComment-85784 Share on other sites More sharing options...
AndyB Posted September 4, 2006 Share Posted September 4, 2006 I've always used lixlpixel's image upload/resize script and create the thumbnails once (at upload time) - http://fundisom.com/phparadise/php/image_handling/image_upload_and_resizeIt works 'straight out of the box'.As for the borders, don't add them to the thumbnails because next week you'll decide you wanted a different colour border. Instead, use some simple CSS to apply padding and a border to the thumbnails when they are displayed. Then next week, change one line of CSS rather than editing a trillion images :) Link to comment https://forums.phpfreaks.com/topic/19593-best-way-image-to-thumbnail/#findComment-85789 Share on other sites More sharing options...
acdx Posted September 4, 2006 Share Posted September 4, 2006 Simple thumbnail generator:[code]<?phpfunction generate_thumbnail($imagefile, $thumb_max_dimension = 200, $quality = 90, $directory = "", $thumb_prefix = "thumb_"){ /* v1.0.1 (by acdx) */ $filename_arr = explode(".", basename($imagefile)); $filetype = $filename_arr[1]; if($filetype == "jpg") $filetype = "jpeg"; if($filetype != "jpeg" && $filetype != "gif" && $filetype != "png") return false; $original_size = getimagesize($imagefile); eval("\$image = imagecreatefrom".$filetype."(\$imagefile);"); if($original_size[0] > $original_size[1]) { if($original_size[0] > $thumb_max_dimension) $thumb_width = $thumb_max_dimension; else $thumb_width = $original_size[0]; $thumb_height = $original_size[1]*($thumb_width/$original_size[0]); } else { if($original_size[1] > $thumb_max_dimension) $thumb_height = $thumb_max_dimension; else $thumb_height = $original_size[1]; $thumb_width = $original_size[0]*($thumb_height/$original_size[1]); } $thumb = imagecreatetruecolor($thumb_width, $thumb_height); imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $original_size[0], $original_size[1]); imagejpeg($thumb, $directory.$thumb_prefix.basename($imagefile).".jpg", $quality); imagedestroy($thumb); imagedestroy($image);}?>[/code]Works with jpg, png and gif files.Note: thumbnails have double extension! Link to comment https://forums.phpfreaks.com/topic/19593-best-way-image-to-thumbnail/#findComment-85812 Share on other sites More sharing options...
SharkBait Posted September 5, 2006 Author Share Posted September 5, 2006 acdx: Ah that works nicely, though it was missing [code=php:0] $image = imagecreatefromjpeg($imagefile); [/code]AndyB: I was using the one you mentioned but it somehow, didnt resize the image properly. But I was able to use it and take bits from what acdx posted and now I have a working thumbnail generator.Thanks :) Now I gota figure out do I create some sorta inline image uploader, or do I just do it seperately and have my article editor select from the database of images? Oh well thats another topic I suppose.Thanks again. Link to comment https://forums.phpfreaks.com/topic/19593-best-way-image-to-thumbnail/#findComment-86536 Share on other sites More sharing options...
acdx Posted September 5, 2006 Share Posted September 5, 2006 Look again...eval("\$image = imagecreatefrom".$filetype."(\$imagefile);"); Link to comment https://forums.phpfreaks.com/topic/19593-best-way-image-to-thumbnail/#findComment-86553 Share on other sites More sharing options...
SharkBait Posted September 5, 2006 Author Share Posted September 5, 2006 I missed that, sorry.Thanks though Link to comment https://forums.phpfreaks.com/topic/19593-best-way-image-to-thumbnail/#findComment-86590 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.