DapperDanMan Posted June 4, 2006 Share Posted June 4, 2006 I am coming across an issue with resizing images using GD. I notice that they are not very clean. Here is an example:GD Resizing:[img src=\"http://oillampstudio.com/element/d_dade/mahsaiid01_jm_tb.jpg\" border=\"0\" alt=\"IPB Image\" /]Photoshop Resizing:[img src=\"http://oillampstudio.com/element/d_dade/mahsaiid01_jm200.jpg\" border=\"0\" alt=\"IPB Image\" /]I am attaching the code (please, I am new to php, so don't yell at me for poor code, please just enlighten me). I am using "imagecreatetruecolor()" which I thought improved image quality as per php.net's snippet (http://us2.php.net/manual/en/function.imagecopyresized.php). I have heard of some plugin thing called magic-something? Is whatever this plugin is called the only way to get good looking resized images?[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php$source_image = $_GET['img_folder'] .$_GET['img_name'];$filename = eregi_replace ('.jpg', '_tb.jpg', $source_image);echo "$source_image<br />";echo "$filename<br />";$im = ImageCreateFromJpeg ($source_image);if (!$im){ echo "Could not generate image"; exit;}//header ('Content-type: image/jpeg');$image_width = ImageSX($im);$image_height = ImageSY($im);$max = 200;echo "Width is: $image_width, Height is: $image_height";if ($image_width >= $image_height) { $prop = ($image_width / $max);}else if ($image_height >= $image_width) { $prop = ($image_height / $max);}echo" <br /> A proportional reduction would be at: $prop";$new_width = ($image_width / $prop);$new_height = ($image_height / $prop);echo "<br /> The new size of the image will be: $new_width wide by $new_height tall.<br>";$thumb = imagecreatetruecolor($new_width, $new_height);imagecopyresized($thumb, $im, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);imagejpeg($thumb, $filename);imagedestroy($thumb);?>[/quote]Any help would be very much appreciated.Thank you,DDM Quote Link to comment https://forums.phpfreaks.com/topic/11138-image-quality-concerns/ Share on other sites More sharing options...
DapperDanMan Posted June 4, 2006 Author Share Posted June 4, 2006 ***SOLVED (I think)***I changed "imagecopyresized" to "imagecopyresampled" and it appears to make the images cleaner when resizing. However, I will still take critiques on my code and if any of you have an even better way to make images look nice, please post it here so that we all can learn.Thank you,DDM[!--quoteo(post=379820:date=Jun 4 2006, 03:37 AM:name=DapperDanMan)--][div class=\'quotetop\']QUOTE(DapperDanMan @ Jun 4 2006, 03:37 AM) [snapback]379820[/snapback][/div][div class=\'quotemain\'][!--quotec--]I am coming across an issue with resizing images using GD. I notice that they are not very clean. Here is an example:GD Resizing:[img src=\"http://oillampstudio.com/element/d_dade/mahsaiid01_jm_tb.jpg\" border=\"0\" alt=\"IPB Image\" /]Photoshop Resizing:[img src=\"http://oillampstudio.com/element/d_dade/mahsaiid01_jm200.jpg\" border=\"0\" alt=\"IPB Image\" /]I am attaching the code (please, I am new to php, so don't yell at me for poor code, please just enlighten me). I am using "imagecreatetruecolor()" which I thought improved image quality as per php.net's snippet (http://us2.php.net/manual/en/function.imagecopyresized.php). I have heard of some plugin thing called magic-something? Is whatever this plugin is called the only way to get good looking resized images?Any help would be very much appreciated.Thank you,DDM[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/11138-image-quality-concerns/#findComment-41650 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.