Home > PHP > PHP Code > Thumbnail image creation using php code

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…!!!”;

You may also like
Multi-language support for web application with MySql and PHP
How to add or remove file fields using jquery
How to calculate statistics in daily, weekly , monthly and yearly using php
How to rectify json_encode returns null in php web services

3 Responses

  1. Pingback : iPad Demonstration / Review Thing Part 1 | Apple On The Longtail

  2. Pingback : Case Study : Upload and crop images with specific dimensions - Anil Labs

Leave a Reply

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