如何使用Image :: Magick调整图像大小以适应区域?

时间:2022-08-13 08:57:01

From command line with imagemagick, you can use:

从带有imagemagick的命令行,您可以使用:

convert dragon.gif -resize 64x64^ -gravity center -extent 64x64 fill_crop_dragon.gif

to resize and then crop an image so that it fills the area as much as possible.

调整大小然后裁剪图像,使其尽可能地填充该区域。

How do I do this from Perl's Image::Magick?

我如何从Perl的Image :: Magick做到这一点?

1 个解决方案

#1


#!/usr/bin/perl

use strict;
use warnings;

use Image::Magick;

my $image = Image::Magick->new;
$image->read('test.jpg');

$image->Set( Gravity => 'Center' );
$image->Resize( geometry => '64x64' );
$image->Extent( geometry => '64x64' );
$image->Write( 'test-out.jpg' );

See the PerlMagick documentation.

请参阅PerlMagick文档。

#1


#!/usr/bin/perl

use strict;
use warnings;

use Image::Magick;

my $image = Image::Magick->new;
$image->read('test.jpg');

$image->Set( Gravity => 'Center' );
$image->Resize( geometry => '64x64' );
$image->Extent( geometry => '64x64' );
$image->Write( 'test-out.jpg' );

See the PerlMagick documentation.

请参阅PerlMagick文档。