开发者

PHP GD - Transparent areas goes black

开发者 https://www.devze.com 2023-03-03 03:47 出处:网络
I am trying to make very simple ISO engine in PHP, my attempts to render in correct place, order etc are succeding however the images drawn, for some reason are black where it should be transparent. P

I am trying to make very simple ISO engine in PHP, my attempts to render in correct place, order etc are succeding however the images drawn, for some reason are black where it should be transparent. PNG files have transparency channel and I am using following test code: http://pastebin.com/TXk4LkJ8 The code is just rough draft.

Files are just 3 faces of an block with dimensions as follows: top - 44x22; sides:23x34

Thank you for your help and I hope the question is clear enough.

Edit: Here is the problem: http://dl.dropbox.com/u/10530011/obraz开发者_高级运维ki/isofail.png

Edit: [SOLVED] For some reason I had to save the images as GIF to make it work. Thank you for your help.


You should call these two functions before saving the png image, imagealphablending() and imagesavealpha():

imagealphablending( $image, false );
imagesavealpha( $image, true );


This answer suggests two things:

  • imagealphablending should be set to false in order to preserve alpha channels
  • You should set the colour you want transparent (in this case black) as transparent:
$black = imagecolorallocate($image, 0, 0, 0);
imagecolortransparent($image, $black);

Do these help?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号