使用Perl拉伸,调整大小或缩放图像

前端之家收集整理的这篇文章主要介绍了使用Perl拉伸,调整大小或缩放图像前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何使用Perl脚本拉伸或调整图像(任何格式)?

解决方法

我推荐 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");

您可能也对Image::Imlib2::Thumbnail感兴趣,如果您无法安装imlib2,请查看Image::Magick

猜你在找的Perl相关文章