Edit report at https://bugs.php.net/bug.php?id=69734&edit=1
ID: 69734
Updated by: cmb@php.net
Reported by: degnan dot 68k at gmail dot com
Summary: transparency sometimes works for PNGs
-Status: Open
+Status: Feedback
Type: Bug
Package: GD related
Operating System: MacOS
PHP Version: 5.4.41
Block user comment: N
Private report: N
New Comment:
I can't access the second image (403 Forbidden). Please double-check the URL, and perhaps
upload the image somewhere else.
Previous Comments:
------------------------------------------------------------------------
[2015-05-30 20:43:00] degnan dot 68k at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=69734&edit=1