php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66005 imagecopy does not support 1bit transparency on truecolor images
Submitted: 2013-10-30 18:41 UTC Modified: 2016-08-21 13:34 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: andreas dot ringlstetter at gmail dot com Assigned: cmb (profile)
Status: Closed Package: GD related
PHP Version: 5.5.5 OS: Linux 3.11.6-1-ARCH x86_64
Private report: No CVE-ID: None
 [2013-10-30 18:41 UTC] andreas dot ringlstetter at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.imagecopy
---

imagecopy() fails to copy transparency from truecolor images if only transparent color is present, but no full alpha channel.

It works as expected for pure palette images and images with full 32bit color depth, but not for the default mixed 24bit + transparency.

imagecopymerge() with 100% handles this transparency type correct. 

Same test was successful on an outdated 5.4.6-1ubuntu1.4.


GD Support 	enabled
GD Version 	bundled (2.1.0 compatible)
FreeType Support 	enabled
FreeType Linkage 	with freetype
FreeType Version 	2.5.0
GIF Read Support 	enabled
GIF Create Support 	enabled
JPEG Support 	enabled
libJPEG Version 	8
PNG Support 	enabled
libPNG Version 	1.6.5
WBMP Support 	enabled
XBM Support 	enabled
WebP Support 	enabled 

Test script:
---------------
<?php
// Create target image
$dest = imagecreatetruecolor(150, 50);
// Fill with transparency
$transparent = imagecolorallocatealpha($dest, 255, 255, 255, 127);
imagealphablending($dest, false);
imagefill($dest, 1, 1, $transparent);
imagesavealpha($dest, true);

imageistruecolor($dest); // true
imagecolortransparent($dest); // == -1

// Palette image with transparent color
$png_palette = imagecreatefromstring(base64_decode('iVBORw0KGgoAAAANSUhEUgAAADIAAAAyAgMAAABjUWAiAAAACVBMVEUAAAD/AAD///9nGWQeAAAAAXRSTlMAQObYZgAAAEFJREFUKM9jYBimIASZIxoagOAwhoaGInisQJ4DksJQJKWoPCAnNIQYHsgChBX4eMSbiddlqH5A9R+q39HCZWgDAFxFGyOrmguhAAAAAElFTkSuQmCCPHP'));
imageistruecolor($png_palette); // false
imagecolortransparent($png_palette); // != -1


// 24 bit with transparent color
$png_24 = imagecreatefromstring(base64_decode('iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAABnRSTlMAAAAAAABupgeRAAAAVklEQVRYw+3UQQqAMBAEwf3/p9eTBxEPiWAmWMU8oGFJqgAAuOpzWTX3xQUti+uRJTZ9V5aY1bOTFZLV7yZr9zt6ibv/qPXfrMpsGipbIy7oqQ8AYJED1plDy5PCu2sAAAAASUVORK5CYII='));
imageistruecolor($png_24); // true
imagecolortransparent($png_24); // 	!= -1

// 32 bit with full alpha channel
$png_full = imagecreatefromstring(base64_decode('iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAXklEQVRo3u3XMQrAIBBFwb3/pU2VwiJNIvjdzMD2PlBwqwAAAGajatxz9OGf5viA+KA3EXExXyKiYlqErIiIiBGSFLIyYmuMkO7Xy2MX4ovS/ONoH7Eh/m1nBwCASBe3VYeVaAy8PwAAAABJRU5ErkJggg=='));
imageistruecolor($png_full); // true
imageistruecolor($png_full); // == -1


imagecopy($dest, $png_palette, 0, 0, 0, 0, 50, 50);
imagecopy($dest, $png_24, 50, 0, 0, 0, 50, 50);
imagecopy($dest, $png_full, 100, 0, 0, 0, 50, 50);

imagepng($dest, 'out.png');


Expected result:
----------------
3 red circles on transparent background, same as in the source images.

Actual result:
--------------
Middle circle has black background, transparent color was ignored on truecolor image.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-21 13:34 UTC] cmb@php.net
-Status: Open +Status: Analyzed -Assigned To: +Assigned To: cmb
 [2016-08-21 13:34 UTC] cmb@php.net
This bug had been fixed in libgd as of 2.1.0-alpha1[1], but the
fix had not been propagated to PHP's bundled libgd.

[1] <https://github.com/libgd/libgd/commit/daac285c>
 [2016-08-21 14:27 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9eb5bbd8bd89caa29ba4fbeb2db27d3e4e05ed79
Log: Fix #66005: imagecopy does not support 1bit transparency on truecolor images
 [2016-08-21 14:27 UTC] cmb@php.net
-Status: Analyzed +Status: Closed
 [2016-10-17 10:09 UTC] bwoebi@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9eb5bbd8bd89caa29ba4fbeb2db27d3e4e05ed79
Log: Fix #66005: imagecopy does not support 1bit transparency on truecolor images
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC