Stretch, resize, or thumbnail an image using Perl

大城市里の小女人 提交于 2019-12-03 12:55:27

问题


How can I stretch or resize an image (of any format) using a Perl script?


回答1:


I'd recommend Image::Imlib2... if you can install imlib2 on your machine

See documentation: 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");

You might also be interested in Image::Imlib2::Thumbnail, if you can not install imlib2 have a look at Image::Magick




回答2:


You could use Image::Resize.



来源:https://stackoverflow.com/questions/486874/stretch-resize-or-thumbnail-an-image-using-perl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!