Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Poor Quality/Wrong Dimensions creating Thumbnail.

Status
Not open for further replies.

blasterstudios

Technical User
Dec 30, 2004
128
US
I would like to create thumbnails from photos as they are uploaded. It seems to be working, however, the thumbnail quality is very poor and it's not the right aspect ratio.
This is the function I'm using to create the thumbs.
Code:
function thumbnail($image_path,$thumb_path,$image_name,$thumb_width)
{
    $src_img = imagecreatefromjpeg("$image_path/$image_name");
    $origw=imagesx($src_img);
    $origh=imagesy($src_img);
    $new_w = $thumb_width;
    $diff=$origw/$new_w;
    $new_h=$new_w;
    $dst_img = imagecreate($new_w,$new_h);
    imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));

    imagejpeg($dst_img, "$thumb_path/$image_name");
    return true;
}

What in here do I need to change to fix the quality and aspect ratio problem?
 
your math for calculating the thumbnail size seems a bit off - you can get better results if you specify maximum sizes for H & W

Also you may find this page handy, but personally I always had best results from .PNG's.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top