ID: 38764 User updated by: markg852 at hotmail dot com -Summary: GD imagecopyresampled() bug Reported By: markg852 at hotmail dot com Status: Open Bug Type: GD related Operating System: Windows XP, linux PHP Version: 5.1.6 New Comment:
The bug is in imagecopyresampled() AND imagecopyresized()!! Previous Comments: ------------------------------------------------------------------------ [2006-09-09 21:45:27] markg852 at hotmail dot com Description: ------------ This bug can be found when trying to make a thumbnail from a url (example: http://promote.opera.com/logos/Opera5_t.png) the png isn`t even transperant anymore unless these 3 lines of code are also added: $background = imagecolorallocate($thumb, 0, 0, 0); ImageColorTransparent($thumb, $background); // make the new temp image all transparent imagealphablending($thumb, false); // turn off the alpha blending to keep the alpha channel i tried everything i could thing of but the quality stays different.. What the code below does is the following: 1. It downloaded the opera logo png image and makes a thumbnail of the URL!! 2. (after hitting F5) the code will make another thumbnail from the downloaded full scale image. 3. (after hitting F5 2nd time) the code will show both thumbnails and look at the quality difference!! and without the 3 lines posted above the "ugly" image has a black background!! Reproduce code: --------------- <?php // Error Reporting error_reporting(E_ALL); // File and new size if (file_exists('thumb_van_url.png') AND file_exists('thumb_van_path.png')) { echo '<img src="./thumb_van_url.png"></img>'; echo "Thumbnail made from URL"; echo '<img src="./thumb_van_path.png"></img>'; echo "This one is made from a PATH"; exit; } elseif (file_exists('./Opera5_t.png')) { $filename = 'Opera5_t.png'; $mid = 'van_path'; } else { $filename = 'http://promote.opera.com/logos/Opera5_t.png'; $mid = 'van_url'; imagepng(imagecreatefrompng('http://promote.opera.com/logos/Opera5_t.png'), 'Opera5_t.png'); } $percent = 0.1; // Get new sizes list($width, $height) = getimagesize($filename); $newwidth = $width * $percent; $newheight = $height * $percent; // Load $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefrompng($filename); $background = imagecolorallocate($thumb, 0, 0, 0); ImageColorTransparent($thumb, $background); // make the new temp image all transparent imagealphablending($thumb, false); // turn off the alpha blending to keep the alpha channel // Resize imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // Output imagepng($thumb, 'thumb_' . $mid . '.png'); echo '<img src="./thumb_' . $mid . '.png"></img>'; // Content type // header('Content-type: image/png'); // readfile('thumb_' . $mid . '.png'); ?> Expected result: ---------------- http://img393.imageshack.us/img393/2796/uitkomstvc4.png ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38764&edit=1