Create Thumbnail Image Dynamically Using PHP

By | May 28, 2014


Create Thumbnail PHP Script

Create Thumbnail Image Dynamically Using PHP

Hello friends earlier we have created the CAPTCHA code example using PHP today here i am putting the tutorial for Create Thumbnail Image Dynamically Using PHP. creating Thumbnail using PHP is very easy and useful in your many projects or applications. You dont have to worry that how you will create thumbnails for gallery just use this code and start working. In this tutorial we are creating the thumbnail after saving the image in the folder than by getting the URL we create the thumbnail of that image. Here we use the GD Library of PHP lets get start.

Step 1. Get Image

As i earlier said that we create the thumbnail of existing image which is saved in our project. Suppose we have an Image folder and in this folder we have an image named “t.gif”. Original Image is of 500px * 250px in size. We will set our parameters so that we will set the thumbnail size.

Let me explain the above code

$rand is used for creating the thumbnail name.

$src is used for getting the URL of the original image.

$dest is used for saving the thumbnail to our new location.

$desired_width & $desired_height is used for setting the thumbnail height.

If you want the thumbnail in proportion than dont set the fixed size just set either the width or the height.

Now we will create our function for creating the thumbnail.

Create Create Thumbnail Image Dynamically Code


If you need the relative height according to the image width than uncomment the below line.

and remove the desired_height parameter from function.

In above example we use the “GIF” Image if you are using the other image type than please change the functions according to the image type.

Call our Create Thumbnail Function

Now everything is setup we have to just call the function and use the function.

Hope you like the post about how to Create Thumbnail Image Dynamically Using PHP. If you have nay suggestions or any feedback or any question than please comment and let me know. Thank you.

~~~~ Happy Codeing ~~~~

Leave a Reply

Your email address will not be published. Required fields are marked *