首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带alpha的PNG 8位gdLib

带alpha的PNG 8位gdLib
EN

Stack Overflow用户
提问于 2009-11-19 17:27:33
回答 6查看 6.1K关注 0票数 8

如何将使用gd创建的图像保存为png-8格式?

它保存为透明通道的gif格式很好-但我想使用png-8。

最好的问候,Beerweasle

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2010-02-24 12:09:48

使用imagesavealpha()和透明的bg颜色应该可以做到这一点…

基于dfilkovi的代码:

代码语言:javascript
复制
<?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);
?>
票数 5
EN

Stack Overflow用户

发布于 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

票数 1
EN

Stack Overflow用户

发布于 2009-11-19 17:52:02

我想这可能会对你有帮助。

http://roseindia.net/tutorial/php/phpgd/About-transparent.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1761986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档