A PHP image resizing script that will resize JPG and PNG images. Specify a width OR a height OR both. Images are resized proportionally if only a width or a height is specified. Great for thumbnails.
A Simple PHP Thumbnail Image Resize Script
I've needed a PHP image resizing script on various projects, and I always seem to spend far too long looking for a simple one to use that just works. This happened one too many times, so I've written my own image resizer script.
Resize proportionally specifying just height or width
- <img src="resize.php?w=150&img=apple.jpg" />
- <img src="resize.php?h=250&img=apple.jpg" />
Resize specifying height and width
Specifying a width and a height will stretch an image to fit these dimensions, it will not crop your images.
- <img src="resize.php?w=150&h=250&img=apple.jpg" />
About the PHP image resize script
It works with both JPG and PNG images, and will resize proportionally to height OR width, and also resize to a specified height and width. So if you have an assortment of images that you all want to be 300 pixels wide, but have varying heights, this script handles it nicely (of course it works if you want to specify a height but not a width as well!).
It's also extremely easy to use. A lot of methods out there make you use round-a-bout ways to resize your images. Mine does not!
Download the PHP resize script.
Important usage note
You must specify the image's full web location. For example, if you view the HTML source of this page, you'll see that
<img src="resize.php?w=200&img=/resources/php-image-resize/apple.jpg >. You cannot simply use
<img src="resize.php?w=200&img=apple.jpg" />.
Update: July 31st, 2012
I've updated the script to allow non-full paths to images. However, I have not performed a lot of testing regarding this. Using a full image path will ensure that caching is handled properly. If you do some testing in this area, please let me know if you discover something interesting!