So, you want to resize an image in PHP? PHP Image resizing has not been so easy especially to newbies so let’s make this as simple as possible. All you have to do is save the script below to a file named ‘imgsize.php’ and give it a try. I use it myself on some of my projects and I wrote the script myself. Some usage examples are listed below after the script.
Click here to VIEW SOURCE CODE. Save file as imgsize.php.
[ads shoppingads computer]
Usage examples:
Resize an image to 25 x 25
imgsize.php?w=25&h=25&img=path/to/image.jpg
Resize an image to 50% the size
imgsize.php?percent=50&img=path/to/image.jpg
Resize an image to 50 pixels wide and autocompute the height
imgsize.php?w=50&img=path/to/image.jpg
Resize an image to 100 pixels tall and autocompute the width
imgsize.php?h=100&img=path/to/image.jpg
Resize to 50 pixels width OR 100 pixels tall, whichever resulting image is smaller
imgsize.php?w=50&h=100&constrain=1&img=path/to/image.jpg
Now enjoy yourself!
Questions, comments, suggestions? Post them below.
P.S. Here’s a user (Brian Marshall) contributed set of instructions on how to use the script. – Read it.