使用Perl对图像进行拉伸、调整大小或制作缩略图

8
我该如何使用 Perl 脚本拉伸或调整大小任何格式的图片?

2
你可能想要谷歌一下这样的问题。 - mac
4
你可以在stackoverflow上谷歌任何问题。但是你也可以在这里问。 - innaM
2
谷歌在这里并没有提供太多帮助,因为有太多的解决方案可用,很难找到一个真正好的。我很高兴有人问了这个问题。因为直到现在我一直使用Image::Resize和GD,但对我来说总是一团糟。Image::Imlib2更适合我的需求! - Boris Däppen
2个回答

8
我建议使用 Image::Imlib2... 如果您的计算机上已安装 Imlib2。
请查看文档:Image::Imlib2
use Image::Imlib2;

# load image from file
my $image = Image::Imlib2->load("in.png");

# get some info if you want
my $width  = $image->width;
my $height = $image->height;

# scale the image down to $x and $y
# you can set $x or $y to zero and it will maintain aspect ratio
my $image2 = $image->create_scaled_image($x,$y);

# save thumbnail to file
$image2->save("out.png");

如果你无法安装Imlib2,可以参考Image::Magick,此外,Image::Imlib2::Thumbnail也值得您的关注。


3

是的.. 很酷也很简单。 :) 我不想提供那个,因为有些人可能没有/ 不想安装该库 嘿嘿 - Ric Tokyo
如果您已经使用GD,那么它是一个不错的接口。但是,如果您需要额外安装GD来制作一些缩略图,我不建议这样做。我在新版本上安装GD时遇到了几个问题...这破坏了我的代码。 - Boris Däppen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接