Resize image with PHP and GD

Image processing is now easy in PHP by using GD library. We can easily resize image, rotate, crop and flip.

In this tutorial, we will learn how to resize an image with fixed width and height.

First, we will get the image information like type of image e.g. jpeg, png, gif.

Now, let’s create an image object from the input image and its type. We will use this object later.

Create a new blank image object usingĀ imagecreatetruecolor with the new width and height.

If the input image is png or gif with transparent background, we need to make our new image transparent.

Now resize the original image.

Finally save the resized image in appropriate format.

So, the entire function should look like,

You may also like...