Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Resizing Images: very poor quality output
Old 06-21-2005, 03:02 PM Resizing Images: very poor quality output
Skilled Talker

Posts: 79
Trades: 0
Hello

I'm making a website for a client which requires resizing artwork.

My problem is that the quality of the resized image is very bad.

For example, this is original image:
http://www.iskm.com/test/test.jpg

It is already smaller than the max width and height restrictions I place on the image. Therefore, it should not be resized at all.

Even so, the quality is reduced!! See here:
http://www.iskm.com/test/index.php

The code which generates the image is this:
PHP Code:
echo '<img src="resize_image.php?image=';
           echo 
urlencode($image);
echo 
'&max_width=400&max_height=600" >' 
What causes the quality reduction? I assume it happens when the resize script (appended for everyone's delight) decompresses, resizes and resizes (which is, roughly what I think resizing scripts do).

I got the script for a PHP book.

Cheers
Hamish

Appended resize script (called resize_image.php):
PHP Code:
<?php

  $image 
$_REQUEST['image'];
  
$max_width $_REQUEST['max_width'];
  
$max_height $_REQUEST['max_height'];

  if (!
$max_width)
    
$max_width 80;
  if (!
$max_height)
    
$max_height 60;

  
$size getimagesize($image);
  
$width $size[0];
  
$height $size[1];



  
$x_ratio $max_width $width;
  
$y_ratio $max_height $height;

  if ( (
$width <= $max_width) && ($height <= $max_height) ) {
    
$tn_width $width;
    
$tn_height $height;
  }
  else if ((
$x_ratio $height) < $max_height) {
    
$tn_height ceil($x_ratio $height);
    
$tn_width $max_width;
  }
  else {
    
$tn_width ceil($y_ratio $width);
    
$tn_height $max_height;
  }

  
$src ImageCreateFromJpeg($image);
  
$dst ImageCreate($tn_width,$tn_height);
  
ImageCopyResized($dst$src0000,
      
$tn_width,$tn_height,$width,$height);
  
header('Content-type: image/jpeg');
  
ImageJpeg($dstnull, -1);
  
ImageDestroy($src);
  
ImageDestroy($dst);

?>
__________________

Please login or register to view this content. Registration is FREE
secure and fully automated computer data backup for small and medium sized companies.


Please login or register to view this content. Registration is FREE

Last edited by hamish; 06-21-2005 at 03:05 PM..
hamish is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-22-2005, 06:05 AM
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Use ImageCreateTrueColor here: $dst = ImageCreate($tn_width,$tn_height);
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 06-23-2005, 12:34 PM
Skilled Talker

Posts: 79
Trades: 0
Thank you very much! That works perfectly.

Kind regards
Hamish
__________________

Please login or register to view this content. Registration is FREE
secure and fully automated computer data backup for small and medium sized companies.


Please login or register to view this content. Registration is FREE
hamish is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Resizing Images: very poor quality output
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11563 seconds with 12 queries