如何使用Perl和GD创建透明的真彩色PNG?(How do you create a transparent truecolor PNG with Perl & GD?)

编程入门 行业动态 更新时间:2024-10-28 04:24:09
如何使用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.

更多推荐

本文发布于:2023-08-02 19:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1379715.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   透明   真彩色   GD   Perl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!