Hello, I want to convert a 1024 x 786 wallpaper into thumbnail in PHP Wots the code for it? Thanx in advance
What makes the page quicker? 1- using php, creating a html tag with calculated width and height; 2- creating a new image, using imagecopyresized? Thanks in advance.
"resize" a image by adding width/height tags to image is pretty noobish. it does not shrink image, the browser just squeezes the full size image small, causing extrem long loading times and poor thumbnail quality. watch and learn: <?php //hail to the king, babe! [URL="http://www.shareyourride.net"]http://www.shareyourride.net[/URL] :) //define the datatype for the browser header("Content-type:image/jpeg"); //find your picture $path = $_GET['path']; //load picture $pic = imagecreatefromjpeg($path); //get size $x = imagesx($pic); $y = imagesy($pic); //create a new image with the given size. this here will scale it down it to //10% (original width * 0.1, original height * 0.1) $pic_small = imagecreatetruecolor($x * 0.1, $y * 0.1); imagecopyresampled($pic_small, $pic, 0, 0, 0, 0, $x * 0.1, $y * 0.1, $x, $y); //send jpeg back to browser imagejpeg($pic_small); //destroy all evidence imagedestroy($pic); imagedestroy($pic_small); ?> Code (markup): save this as a new file "resize.php", it must be in the same folder as your gallery.php. this is the code for your gallery site to display the thumbnail: <img src="resize.php?path=test.jpg"> HTML: thats all. test.jpg is the name of the image you want to resize here.
the best option is to make a script to make a thumbnail for the image when it is uploading. name it with the same filename like the original image, but with _tn at the end, or something like this, and you will have 2 images, original and thumbnail to work with.
Thank you very much falcondriver. I've changed the way I show images in the articles of my WW2 website. I think it's much faster than before.
you've hit on a decent point, actually. creating the image does take up resources on the server, especially if it's a high traffic site and you're doing this over and over again. in that case, if possible, you'd want to cache the images that're created to save some resources.
What makes the page quicker? 1- using php, creating a html tag with calculated width and height; 2- creating a new image, using imagecopyresized? Best is to create thumbs when you upload the images and load does.
This function creates the thumbnail and saves the image to disk to lower processing need: http://www.phptricks.com/index.php?lesson_id=14§ion=2 Peace,
When I wrote my last post, I wasn't aware of the GIF problem. So I had to change the code to work 100% with any type of image (at least, jpg, gif and png...I only use these three types). Now...I notice the website is faster than without this resize issue. Thank you all.
phpThumb is a great set of scripts which I think would do everything you need: http://phpthumb.sourceforge.net/