I'm trying to use this to change my thumbs to a set size of W:160 H:120 (landscape) and W:120 L:160 (portrait) but every time I upload it makes my website blank.
Where should the getimagesize() command be implemented if I want to use it to get all image sizes?
This is a horrible example... You aren't actually making thumbnails, you are still sending the full size image and having the browser resize it.. BS sitepoint!
About the datatraffic. On my site I use the image in several dimensions. On the homepage I have a Flash news scroller/reader with a relatively large dimensions (a).
In the newsposts below I use a rather smaller image (b). When posting a newsitem in the admin it uploads the image to the server twice according the dimansions a and b.
I also use a 3rd dimension of the image on the archive page. I do not want to upload the image in 3 different dimensions via the admin. So I use the code above to resize the image (with dimensions b) to this 3rd dimension.
The datatraffic isn't that bad. The site wherefor I'm using it attracts 1000+ unique visitors and this seems to be the best solution.
The script manages ratios the way it should, but you should not be resizing your images in your HTML! That's the big thing here. With the image functions available in PHP, you can dynamically create a new, temporary image just for the display of the needed use. Otherwise, you're still downloading the FULL SIZE image and the browser is manipulating it via deprecated standards. Bad form. GREAT IDEA. A little more effort into the image library and this would be awesome.
Hi, this is a good script, simple to use and it's a good base for building a more tailored solution.
As many people have pointed out this resizes the image and it mixes style and content - something we normally avoid. However, I think this is better than simply forcing a set size in CSS as the results are better.
Also, it has the advantage of working with all image formats whereas most scripts that resize images and create new files only support one file - typically jpg.
My recommendation for storing images of the size you want is to resize them before you upload them to your site. That way you get the file size you want. If you apply this idea with this script you can resize the file to the max size you are going to support on your site and then use the scrip to resize for thumbnails.
nathj
This is horrible. Resizing an image is as much about saving bandwidth as it is about page layout. Using an html-scaled large image for a user on dialup is going to pain them to the point of never returning and tripple your bandwidth charges. You should just batch resize them into several general size (small, med, large) at the very least r use GD to resize uploaded images.
For those of you who don't understand much about advanced PHP. I've made an easy to use script that you can install on you server. It uses a Graphical user interface (PHP + HTML) for the settings and handles pretty much all your needs in term of image croping/resizing/compressing.
You can find it here PictoPHP.com . Let me know what you think.
Cheers.
Actually I am looking for some different type of resize script.
Ex. I do not want to resize height and width but I want to resize size in KB.
Ex. if some image is greater then 200KB then I want to reduce that image by resizing resolution without changing height and width to make its size to near 200KB.
I think it is technically impossible to resize an image to a specific weight (in kb) . The only way to do this would be to make a script that would shrink the image each time by say 10% and check the new weight of the image.
Calculation involved in image compression algorithm can not be '2 ways'. (Can't determine the input variables having the output result)
So your best bet would be to 'brute force it' and go with trial/errors.
Hope you have plenty of CPU on you server : )
I don't think simply having the width & height resized is going to make the actual image smaller... so if you have a 1MB image and simply constrain the HTML tag using your returned height and width - it's still going to laod all 1MB of that image!
Good article, but one thing - if you have high traffic website, resizing images on the fly will kill the server, so for low traffic this would work, but for high traffic you should resize on upload and save few copies. It is more important to have fast site, then site that is slow but weight less!
Bookmarks