使用 PHP GD 制作 alpha PNG
我在使用 PHP GD 制作 alpha PNG 时遇到问题。我没有 imageMagik 等。
虽然图像在浏览器和 GFX 程序中加载得很好,但我在 Flash AS3 (actionscript) 理解文件时遇到了问题。它抱怨自己是一种未知类型。但是,将这些文件从 Fireworks 导出到相同的规范效果很好。所以我建议 PHP GD 中的格式有问题。
似乎有很多方法可以做到这一点,并且具有一些相似的功能;所以也许这是不对的?
$image_p = imagecreatetruecolor($width_orig, $height_orig);
$image = imagecreatefrompng($filename);
imagealphablending($image_p, false);
ImageSaveAlpha($image_p, true);
ImageFill($image_p, 0, 0, IMG_COLOR_TRANSPARENT);
imagealphablending($image_p, true);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width_orig, $height_orig, $width_orig, $height_orig);
imagepng($image_p, "new2/".$filename, 0);
图像销毁($image_p);
这只是获取给定的文件并将它们放入具有指定宽度/高度的新文件中 - 对于此示例,它与原始文件相同,但在生产中它会调整大小,这就是我重新采样的原因。
I've got a problem making alpha PNGs with PHP GD. I don't have imageMagik etc.
Though the images load perfectly well in-browser and in GFX programs, I'm getting problems with Flash AS3 (actionscript) understanding the files. It complains of being an unknown type. But, exporting these files from Fireworks to the same spec works fine. So I'm suggesting it's something wrong with the formatting in PHP GD.
There seems to be a number of ways of doing this, with several similar functions; so maybe this isn't right?
$image_p = imagecreatetruecolor($width_orig, $height_orig);
$image = imagecreatefrompng($filename);
imagealphablending($image_p, false);
ImageSaveAlpha($image_p, true);
ImageFill($image_p, 0, 0, IMG_COLOR_TRANSPARENT);
imagealphablending($image_p, true);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width_orig, $height_orig, $width_orig, $height_orig);
imagepng($image_p, "new2/".$filename, 0);
imagedestroy($image_p);
This just takes files it's given and puts them into new files with a specified width/height - for this example it's same as original but in production it resizes, which is why I'm resampling.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了保持透明度,你应该这样做
而不是“true”。也许这也能解决格式问题。
To keep the transparency you should do
instead of "true". Maybe that will solve the format problem too.