Who likes this?

Resizing an Image Using PHP

To use the resize function you must pass in the forced width, forced height, source image, and destination image. The function then uses the GD2 library functions to read the source image's size. It will then calculate the new image's size based off of the forced width and height. This function will maintain the original image's aspect ratio so your image won't look distorted. It won't change the source image at all but when the function is done running you will end up with the destination image which is resized to the dimensions you passed into the function. As far as I know, this function requires the GD2 library although you might be able to get it to work with the GD1 library. The GD library extension must be enabled in PHP before you can use GD2 functions so keep that in mind as well. You can use the PHP function phpinfo() to see if GD2 is enabled or to see what version of the GD library your server is using.

Comments

This function is a bit limited in that it only works for jpeg files...

You can use if-statements to check which image you're using. Go check this function I made here on Snipplr, it'll help you out:

For instance, you can check for PNG files like this: endsWith(".png",$file,false);
Then, if you have a PNG for instance, simple do an createimagefrompng(), which excists, just like createimagefromgif() exists.