944,221 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 11896
  • PHP RSS
Oct 17th, 2005
0

php image resize quality

Expand Post »
I try to use PHP GD library to resize image to thumbnail size, however I found the small converted image has bad quality(distorted color), how can I improve the image quality by using PHP GD library:
PHP Syntax (Toggle Plain Text)
  1. $first=imagecreatefromjpeg($uploadfile);
  2. define(MAX_WIDTH, 180);
  3. define(MAX_HEIGHT, 135);
  4. $width = imagesx($first);
  5. $height = imagesy($first);
  6. $scale = min(MAX_WIDTH/$width, MAX_HEIGHT/$height);
  7. $new_width = floor($scale*$width);
  8. $new_height = floor($scale*$height);
  9. $second=imagecreate($new_width, $new_height);
  10. imagecopyresized($second,$first,0,0,0,0,$new_width,$new_height,$width,$height);
  11. imagejpeg($second,$v_thumbnailfile);

Thanks for any response.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
michael123 is offline Offline
93 posts
since Jun 2005
Oct 18th, 2005
0

Re: php image resize quality

Can anyone answer my question?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
michael123 is offline Offline
93 posts
since Jun 2005
Mar 20th, 2010
0

function can have 3rd parameter for quality

imagejpeg()
function can have 3rd parameter for quality
so use it as
imagejpeg($second,$v_thumbnailfile, 100);


Click to Expand / Collapse  Quote originally posted by michael123 ...
I try to use PHP GD library to resize image to thumbnail size, however I found the small converted image has bad quality(distorted color), how can I improve the image quality by using PHP GD library:
PHP Syntax (Toggle Plain Text)
  1. $first=imagecreatefromjpeg($uploadfile);
  2. define(MAX_WIDTH, 180);
  3. define(MAX_HEIGHT, 135);
  4. $width = imagesx($first);
  5. $height = imagesy($first);
  6. $scale = min(MAX_WIDTH/$width, MAX_HEIGHT/$height);
  7. $new_width = floor($scale*$width);
  8. $new_height = floor($scale*$height);
  9. $second=imagecreate($new_width, $new_height);
  10. imagecopyresized($second,$first,0,0,0,0,$new_width,$new_height,$width,$height);
  11. imagejpeg($second,$v_thumbnailfile);

Thanks for any response.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fahad.mahmood is offline Offline
1 posts
since Mar 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Making a chatroom without mysql
Next Thread in PHP Forum Timeline: updating the leave





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC