Thumbnail image creation using php code

In this post explains how to create thumbnail image using php code.

function make_thumb($img_name,$filename,$new_w,$new_h)
//get image extension.
//creates the new image using the appropriate function from gd library
if(!strcmp(“jpg”,$ext) || !strcmp(“JPG”,$ext) || !strcmp(“jpeg”,$ext) || !strcmp(“JPEG”,$ext))

if(!strcmp(“gif”,$ext) || !strcmp(“GIF”,$ext))

if(!strcmp(“png”,$ext) || !strcmp(“PNG”,$ext))

//gets the dimmensions of the image


if($ratio1>$ratio2) {
else {
// we create a new image with the new dimmensions

// resize the big image to the new created one

// output the created image to the file. Now we will have the thumbnail into the file named by $filename

//destroys source and destination images.


To find out the extension of image with following function:

function getExtension($str) {
$i = strrpos($str,”.”);
if (!$i) { return “”; }
$l = strlen($str) – $i;
$ext = substr($str,$i+1,$l);
return $ext;

Call the particular thumbnail function like :

echo “Thumbnail created successfully…!!!”;

Anil Kumar Panigrahi

With more than 10 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ... Contact : [email protected]

You may also like...

3 Responses

  1. GP Code library
    Create thumbnail image by php
    When we upload large size images on server. Uploaded large images take more time to load on webpage, so we need to show small size images on our webpage. Image thumbnail is a solution to generate uploaded image’s thumbnail to show required size images on our website.

  1. June 3, 2010

    […] Thumbnail image creation using php code « ANIL KUMAR PANIGRAHI 's Blog […]

  2. August 31, 2015

    […] Thumbnail image creation using PHP code […]

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.