如何将使用gd创建的图像保存为png-8格式?
它保存为透明通道的gif格式很好-但我想使用png-8。
最好的问候,Beerweasle
发布于 2010-02-24 12:09:48
使用imagesavealpha()和透明的bg颜色应该可以做到这一点…
基于dfilkovi的代码:
<?php
// Create a new true color image
$im = new imagecreatetruecolor(100, 100);
// Fill with alpha background
$alphabg = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $alphabg);
// Convert to palette-based with no dithering and 255 colors with alpha
imagetruecolortopalette($im, false, 255);
imagesavealpha($im, true);
// Save the image
imagepng($im, './paletteimage.png');
imagedestroy($im);
?>发布于 2010-08-14 00:55:51
@桑尼
错误假设:任何位深度的PNG都可以具有透明性。它被记录在png图像的tRNS块中(真彩色图像除外) cf格式定义
cf www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html#C.tRNS
同上www.w3.org/TR/PNG-Chunks.html#C.tRNS
不同之处在于它是记录器: RGBA每个像素有一个唯一的记录,有4个值(3种颜色和1个alpha通道),其中"paletted“PNG在它自己的块中记录alpha通道。
Fireworks在这方面做得很好。
示例:
http://www.libpng.org/pub/png/pngs-img.html
发布于 2009-11-19 17:52:02
我想这可能会对你有帮助。
http://roseindia.net/tutorial/php/phpgd/About-transparent.html
https://stackoverflow.com/questions/1761986
复制相似问题