Edit report at https://bugs.php.net/bug.php?id=23815&edit=1
ID: 23815
Updated by: cmb@php.net
Reported by: bjorn at smokingmedia dot com
Summary: imagecopymerge doesn't respect alpha-channel in
PNG-24 file
-Status: Assigned
+Status: Suspended
Type: Feature/Change Request
Package: GD related
Operating System: Linux pluto 2.4.18lvm-r1
PHP Version: 5.2.9
Assigned To: pajoye
Block user comment: N
Private report: N
New Comment:
IMHO, imagecopymerge() should finally be removed in the long run.
Its purpose is to emulate alpha, what was necessary before GD
introduced truecolor images with proper alpha channels. Therefore,
I'm against adding further alpha support to imagecopymerge() or
even an additional function.
Instead, imagefilter() could be used to either increase the alpha
values or to decrease the color values. IMG_FILTER_COLORIZE already
allows this, but one can't specify a percentage, so can't get the
exact same effect. The following example shows that one could already
come a long way, though:
<?php
$bg = imagecreatefrompng(__DIR__ . '/23815-bg.png');
$over = imagecreatefrompng(__DIR__ . '/23815-over.png');
imagecopy($bg, $over, 0, 0, 0, 0, 16, 32);
imagealphablending($over, false);
imagefilter($over, IMG_FILTER_COLORIZE, 0, 0, 0, +32);
imagecopy($bg, $over, 16, 0, 0, 0, 16, 32);
imagepng($bg, __DIR__ . '/23815-out.png');
Anyhow, this is a general libgd issue (not particularly related to
PHP's bundled libgd), so I have filed
<https://github.com/libgd/libgd/issues/370>
and suspend this
feature request.
Previous Comments:
------------------------------------------------------------------------
[2012-10-04 07:24:52] cleggmatt at gmail dot com
Good idea. Added as an extra function and created a pull request on github
https://github.com/php/php-src/pull/211
------------------------------------------------------------------------
[2010-05-06 06:44:55] setvik at gmail dot com
I have the same need to merge alpha images with the opacity of the top one
reduced, and like the others in this thread, I assumed imagecopymerge would
respect the alpha settings in the image. Based on comments here and in the docs
( http://php.net/manual/en/function.imagecopymerge.php),
others are making the
same assumption.
@pajoye - The inclusion of alpha support whether in imagecopymerge or an
additional function would be very valuable for working with images, especially
watermarks with complex transparency. Any chance imagecopymerge can be patched
to support this? Or should an additional function be written and the
documentation for imagecopymerge updated?
What's your take?
------------------------------------------------------------------------
[2009-12-10 18:35:56] andre at webkr dot de
Ah, I see. It's imagecopy() which implements alpha transparency while imagecopymerge() does
not.
------------------------------------------------------------------------
[2009-12-10 18:23:20] andre at webkr dot de
So what does the "it implements alpha transparency for true colour images" in "When
pct = 0, no action is taken, when 100 this function behaves identically to imagecopy() for pallete
images, while it implements alpha transparency for true colour images." mean anyway?
------------------------------------------------------------------------
[2009-07-20 12:10:43] steve at redmonkey dot org
Thanks, understood. Although, I do think it would be a useful feature, perhaps there's scope
for an 'imagecopymergealpha' type function in the future?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=23815
--
Edit this bug report at https://bugs.php.net/bug.php?id=23815&edit=1