|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20847 subimages made from transparent images aren' transparent
Submitted: 2002-12-05 17:49 UTC Modified: 2002-12-05 19:19 UTC
From: gid at gifpaste dot net Assigned: pajoye (profile)
Status: Closed Package: GD related
PHP Version: 4.3.0RC2 OS: Debian (sid) Linux 2.4.20
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: gid at gifpaste dot net
New email:
PHP Version: OS:


 [2002-12-05 17:49 UTC] gid at gifpaste dot net
I'm running 4.3.0RC2 with the built in gd library.

What I'm trying to do is create a transparent subimage from a series of pngs that have an 8 bit alpha channel.  I then can resize the subimage, rotate it, whatever over another photograph.

I realize there's the imagecolortransparent() function so you can specify one color on your image as transparent, but this does not help the case when you want full 8-bit transparency.

Expected results:  The subimage should have an 8-bit alpha channel like the png's that's it's created from and should be transparent when imagecopy()'d over the photoimage.

Actual results:  I get a black box where I tried to copy the image.

Web page source:
(example png and jpg images I used are loacated here)

Example source:
// load photo image
$photo_img = imagecreatefromjpeg('images/kittybath.jpg');
imagealphablending($photo_img, TRUE);

// load just one letter for now to test
// this is a transparent png with an 8 bit alpha channel
$letter_img = imagecreatefrompng('images/S.png');
imagealphablending($letter_img, TRUE);
$x = imagesx($letter_img);
$y = imagesy($letter_img);

// create the words image, same size as the letter for now
// this is also referred to as the subimage, it should also have an 8 bit alpha channel
// like the letter_img
$words_img = imagecreate($x, $y);
imagepalettecopy($words_img, $letter_img);
imagealphablending($words_img, TRUE);

// copy letter image onto words image
imagecopy($words_img, $letter_img, 0, 0, 0, 0, $x, $y);

// now that we have the words image, we can resize it, rotate it, etc
// but we won't do that for now to keep things simple

// copy words image onto photo image
imagecopy($photo_img, $words_img, 50, 50, 0, 0, $x, $y);

// write out new image
imagejpeg($photo_img, 'images/new.jpg', 90);


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-05 17:52 UTC] gid at gifpaste dot net
Additional note:  If I try to directly copy the transparent png image over the photo image, it works like a charm, it's only when I need to create an intermediate subimage that it doesn't work.
 [2002-12-05 19:19 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.


You may use color to draw something in a image, not only alpha channels. Paint program shows you a black/gray for ot as a convenience.

Try to redraw your letter with real color (even with transparancy) and it will work.

Thank's for your report.


PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon May 23 15:05:45 2022 UTC