<? //This is your source file path
$source_file = "VW_Beetle_Sport_Concept_by_husseindesign.jpg";
//To get the image width and height if you want to resize
the image with a perfect ratio and etc..
list($img_width,$img_height) = getimagesize($source_file);
//Create a new true color image
$im = @imagecreatetruecolor($img_width, $img_height) or
die('Cannot Initialize new GD image stream');
//Create a new image from file or URL
$img_source = imagecreatefromjpeg($source_file);
//Copy and resize part of an image with resampling
imagecopyresampled($im, $img_source, 0, 0, 0, 0, $img_width, $img_height,
//Output image to browser or file
//Destroy an image imagedestroy($im); imagedestroy($img_source); ?>
In the above code
is the function which will reduce the image size;
We can change the third parameter sent to the function call
which is currently set to “90
” to reduce the image size accordingly.
NOTE: This parameter controls the image quality so we need to focus on that
factor while setting this up. But you can see the example mentioned below to
find the significant change in size of two images.
This page has two links: one is to the original image which is of 515 KB and
another one is the converted image using the above code which is of 147 KB.
So you can see the difference in size with a very negligible quality difference.