できたら教えてください。
http://search.cpan.org/perldoc?Imager::Cookbook#Transparent_PNG
To make a transparent image, create an image object with 2 or 4 channels:
# RGB with alpha channel my $rgba = Imager->new(xsize => $width, ysize => $height, channels => 4); # Gray with alpha channel my $graya = Imager->new(xsize => $width, ysize => $height, channels => 2);By default, the created image will be transparent.
最後の行にあれっ?と思ったが、デフォルトのチャンネルは3、つまり透過を表すアルファチャンネルがないのは確か。
http://search.cpan.org/perldoc?Imager::ImageTypes#Creating_Imager_Objects
channels - The number of channels for the image. Default 3. Valid values are from 1 to 4.
たぶん、アルファチャンネル付きだと、作成時は全域が透過状態という意味なのでしょう。
特に追加しなければならないモジュールはないと思います。
2013/03/31 00:30:39私の所では以下で周囲が透明なpng画像が出来ています。
#!/usr/bin/perl
2013/03/31 13:13:00use Imager;
my $string = "ああああ";
my $font = Imager::Font->new(
file => '/home/XXXX/public_html/font/font001.TTF',
color => '#000000',
size => 60,
);
my $bbox = $font->bounding_box(string => $string); # 文字情報を取得
my $img = Imager->new(xsize => $bbox->total_width*1.1, ysize => 70, ,channels => 4);←これを付けて、、
#↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
#$img->box(filled => 1);←←これを消したらできました。
#↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
$img->string(
string => $string,
utf8 => 1,
font => $font,
x => 0,
y => 60,
aa => 1,
);
print "Content-type: image/png\n\n";
print $img->write(fh => \*STDOUT, type => 'png') or die $img->errstr;
変なボックスを描画していたからできなかったのですね。
ありがとうございます