We help IT Professionals succeed at work.
Get Started

Quality loss in resized image

RajeshKanna asked
Last Modified: 2012-05-09
Hi all,

I am using a script to resize images bulk from one folder and stored in another folder.

While I resize the large size images in to the dimension of 525x330 there is no quality loss.

But I resize the small size image to the dimension of 525x330 there is quality loss...

Can any body help  over this..

Thanks in advance...
#  * usage: 
#  * resize.php [destination_width] [destination_height] 
#  * 
#  * destination_width and destination_height are optional 
#  * parameters for destination resize geometry 
#  * 
#  * resize.php will create output directory to save resized 
#  * images leaving originals intact 
#  * 
#  * This script uses "identify" and "convert" utilities which 
#  * are members of the ImageMagick suite of tools 
#  * 
#  */  
# // input arguments for destination image size  
 $w2 = $argv[1]; // image width  
 $h2 = $argv[2]; // image height  
# // both values should be numeric or use default size 800x600  
 if (!is_numeric($w2) || !is_numeric($h2)){  
   $w2 = 150; // default image width  
   $h2 = 190; // default image height  
# // prepare directory name for saving resized images  
# // directory name will look like "_800x600"  
 $dir = "Image";  
# // create directory (inside current directory) for saving  
# // resized images (@ means to be quiet - don't display  
# // warning if directory alredy exists)  
# // read files inside current directory  
 $files = scandir('.');  
# // open loop for all fetched files in current directory  
 foreach ($files as $file){  
#   // convert file name to lower case  
   $file_lowercase = strtolower($file);  
#   // if file extension is jpg then process image  
   if (substr($file_lowercase, -3) == 'jpg'){  
#     // describe image format and image characteristics  
     $identify = shell_exec("identify $file");  
#     // read image geometry  
     preg_match('/(\d+)x(\d+)/', $identify, $matches);  
     $g1 = $matches[0]; // image geometry  
     $w1 = $matches[1]; // image width  
     $h1 = $matches[2]; // image height  
#     // prepare destination image geometry  
     if ($w1 < $h1) $g2 = $h2 .'x' .$w2;  
     else           $g2 = $w2 .'x' .$h2;  
#     // print current image status  
     print "$file ($g1) -> $dir/$file_lowercase ($g2)\n";  
#     // resize image and save to destination directory  
     system("convert -size $g1 $file -resize $g2 $dir/$file_lowercase");  
# ?>

Open in new window

Watch Question
Most Valuable Expert 2011
Author of the Year 2014
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE