View Single Post
Old 10-10-2012, 09:30 PM   PM User | #1
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
Exclamation thumbnail script is producing poor quality thumbs please help

Hi All,
i have a thumbnail generator function

PHP Code:
function createThumbs$pathToImages$pathToThumbs$thumbWidth )
{
  
// open the directory
  
$dir opendir$pathToImages );

  
// loop through it, looking for any/all JPG files:
  
while (false !== ($fname readdir$dir ))) {
    
// parse path for the extension
    
$info pathinfo($pathToImages $fname);
    
// continue only if this is a JPEG image
    
if ( strtolower($info['extension']) == 'jpg' )
    {
      
#echo "Creating thumbnail for {$fname} <br />";

      // load image and get image size
      
$img imagecreatefromjpeg"{$pathToImages}{$fname}" );
      
$width imagesx$img );
      
$height imagesy$img );

      
// calculate thumbnail size
      
$new_width $thumbWidth;
      
$new_height $thumbWidth;#floor( $height * ( $thumbWidth / $width ) );

      // create a new temporary image
      
$tmp_img imagecreatetruecolor$new_width$new_height );

      
// copy and resize old image into new image
      
imagecopyresized$tmp_img$img0000$new_width$new_height$width$height );

      
// save thumbnail into a file
      
imagejpeg$tmp_img"{$pathToThumbs}{$fname}" );
    }
  }
  
// close the directory
  
closedir$dir );
}
?> 
the thumbnails that are created are created by resizing the width and height to a set size 148px in my case. so it creates a square.

now because its just resizing the images they are distorted and dont look as good as they could/should. i looked on facebooks gallery and they have a square thumbnail image similar to mine but it is perfect no stretched images and the main part of the image is always in shot and quite close up.

so my question is how do i modify the above function to produce better quality thumbnails?

many thanks
Luke
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook

Last edited by LJackson; 10-11-2012 at 11:58 AM..
LJackson is offline   Reply With Quote