PHP Image Resizing…

I have been searching for some time an easy way to change the size of jpg and png images on the fly – on the server. currently my preferred solution is the PHP Image resize script found here ..

The solution is extremely easy to implement. I use it to convert almost 1000 images whos filenames have stored in the database (on the fly).

Have found the following issues though:

  1. All of my images are google optimized (using jpegtran and optipng). After the conversion the new file is 10 times larger in size even though the  dimensions are similar (197×50 and 6kb to 200×50 and 30kb size). So there goes my optimization…
  2. I have manually converted most of my files to width 200 to match my web site layout. When an already 200pixels image passes from the script that sets it to comvert again to 100px,  it sometimes produces a blank png file with, and some times the quality of the image is very bad (even though you set it to convert with the highest quality). I will need to investigate this why the script behaves differently to different png  files if i wanna keep it.
$resizedFile="./brands/".$row_Recordset1['NAME']."/".strtolower(str_replace ( ' ', '-', $row_Recordset1['NAME']))."_reslogo.png";

list($width, $height) =getimagesize($file);

echo $width;

//echo $height;

if (file_exists($file)){


if (file_exists($resizedFile)){

//to nothing

}else {

smart_resize_image($file , null, 201 , null , true , $resizedFile , false , false ,100 );

Update: Found that issue #2 was caused by the fact that i was scaling the image up, rather than down.  Issue #1 still persists though.

Here is a very informative post about the jpg image optimization and resizing using php native functions


Leave a Reply