【发布时间】:2011-06-21 12:11:54
【问题描述】:
这是我正在使用的代码:
!/usr/bin/perl
use GD;
sub resize
{
my ($inputfile, $width, $height, $outputfile) = @_;
my $gdo = GD::Image->new($inputfile);
## Begin resize
my $k_h = $height / $gdo->height;
my $k_w = $width / $gdo->width;
my $k = ($k_h < $k_w ? $k_h : $k_w);
$height = int($gdo->height * $k);
$width = int($gdo->width * $k);
## The tricky part
my $image = GD::Image->new($width, $height, $gdo->trueColor);
$image->transparent( $gdo->transparent() );
$image->copyResampled($gdo, 0, 0, 0, 0, $width, $height, $gdo->width, $gdo->height);
## End resize
open(FH, ">".$outputfile);
binmode(FH);
print FH $image->png();
close(FH);
}
resize("test.png", 300, 300, "tested.png");
输出图像为黑色背景,所有 Alpha 通道均丢失。
我正在使用这张图片:http://i54.tinypic.com/33ykhad.png
这是结果:http://i54.tinypic.com/15nuotf.png
我尝试了 alpha() 和 transparancy() 等的所有组合,但都没有奏效.....
请帮我解决这个问题。
【问题讨论】: