From:             markg852 at hotmail dot com
Operating system: Windows XP, linux
PHP version:      5.1.6
PHP Bug Type:     GD related
Bug description:  GD imagecopyresampled() bug

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 bug report at http://bugs.php.net/?id=38764&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=38764&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=38764&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=38764&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=38764&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=38764&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=38764&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=38764&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=38764&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=38764&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=38764&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=38764&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=38764&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=38764&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=38764&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=38764&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=38764&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=38764&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=38764&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=38764&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=38764&r=mysqlcfg

Reply via email to