如何使用Perl和GD创建透明的真彩色PNG?(How do you create a transparent truecolor PNG with Perl & GD?)
这似乎是一个微不足道的问题,但我尝试过的任何事情都不会使背景变得透明。
use strict; use warnings; use GD GD::Image->trueColor(1); my $im = new GD::Image(100, 100); my $clear = $im->colorAllocateAlpha(255, 255, 255, 127); my $black = $im->colorAllocateAlpha(0, 0, 0, 0); $im->alphaBlending(0); $im->filledRectangle(0, 0, 100, 100, $clear); $im->alphaBlending(1); $im->stringFT($black, "a-ttf-font.ttf", 12, 0, 20, 20, "x"); binmode STDOUT; print $im->png;感谢您的指导。
It seems like a trivial problem, but nothing I've tried will make the background transparent.
use strict; use warnings; use GD GD::Image->trueColor(1); my $im = new GD::Image(100, 100); my $clear = $im->colorAllocateAlpha(255, 255, 255, 127); my $black = $im->colorAllocateAlpha(0, 0, 0, 0); $im->alphaBlending(0); $im->filledRectangle(0, 0, 100, 100, $clear); $im->alphaBlending(1); $im->stringFT($black, "a-ttf-font.ttf", 12, 0, 20, 20, "x"); binmode STDOUT; print $im->png;Thanks for any guidance.
最满意答案
你在使用$im->saveAlpha(1)吗? 否则,alpha信息仅在构建图像时有用。 保存的图像不会透明。
一个快速而肮脏的方法,可能不适合您的目的,是忘记alpha通道并使用GD::Image::transparent方法。
Are you using $im->saveAlpha(1)? Otherwise the alpha information is only useful in constructing the image. The saved image won't be transparent.
A quick and dirty method, which might not be good enough for your purposes, is to forget about the alpha channel and use the GD::Image::transparent method.
更多推荐
发布评论