Bug #69734 [NEW]: transparency sometimes works for PNGs

From: Date: Sat, 30 May 2015 20:43:01 +0000
Subject: Bug #69734 [NEW]: transparency sometimes works for PNGs
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193017@lists.php.net to get a copy of this message
From:             degnan dot 68k at gmail dot com
Operating system: MacOS
PHP version:      5.4.41
Package:          GD related
Bug Type:         Bug
Bug description:transparency sometimes works for PNGs

Description:
------------
Two PNG files handled the same way, and one works with transparency and
the other does not.  The included code cuts a transparent "hole" in each
file, but only one has the red back ground show through.

I'll be happy to look into patching it, but I need to confirm it's a
problem.  It show this behavior on all of my machines, but I cannot
determine if it's a PHP or a libgd issue.



Test script:
---------------
<?php
sometimesworks("https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=400x400&maptype=hybrid",
"google");
sometimesworks("https://lh4.googleusercontent.com/UQvV_dpBa3_rVf25pvLXKD3OwzF4FtPnHBHkzdWqjCQ5mlFqcFfId9echIgDMv_xYRRYzLaKEXphw7g=w2447-h1106",
"myhouse");

function sometimesworks($p_image, $p_prefix)
{
$image_top =imagecreatefrompng($p_image);
$brush = imagecolorallocate($image_top, 0, 0, 0);  //create a black
brush
imagefilledpolygon($image_top, explode(",", "10,10, 120,22, 80,280, 200,
191"), 4, $brush);  //fill a polygon
imagecolortransparent($image_top, $brush);  //turn the black to be
transparent
imagepng($image_top, './'.$p_prefix.'.transparent.png');  //save the
file to confirm that it is working.

//create a big red square
$image_bottom = imagecreatetruecolor(imagesx($image_top),
imagesy($image_top));
$red = imagecolorallocate($image_bottom, 255, 0, 0);
imagefill($image_bottom, 0, 0, $red);
imagepng($image_bottom, './'.$p_prefix.'.red.png');

//merge the top onto the bottom.
$out = imagecreatetruecolor(imagesx($image_top), imagesy($image_top));
imagecopy($out, $image_bottom, 0, 0, 0, 0, imagesx($image_top),
imagesy($image_top));
imagecopy($out, $image_top, 0, 0, 0, 0, imagesx($image_top),
imagesy($image_top));
imagepng($out, './'.$p_prefix.'.out.png');
}

Expected result:
----------------
Both files should have red seen through the alpha mask holes in the PNG
images.

Actual result:
--------------
One file shows transparency, and the other does not; however, the code
is identical as function.  Only the files are different.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=69734&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=69734&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=69734&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=69734&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=69734&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=69734&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=69734&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=69734&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=69734&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=69734&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=69734&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=69734&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=69734&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=69734&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69734&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=69734&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=69734&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=69734&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69734&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=69734&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=69734&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#193017) next »