PHP GD - Transparent areas goes black

◇◆丶佛笑我妖孽 提交于 2019-12-07 02:51:52

问题


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/obrazki/isofail.png

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


回答1:


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

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



回答2:


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?



来源:https://stackoverflow.com/questions/5913284/php-gd-transparent-areas-goes-black

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!