我正在尝试使用 ImageMagick 来扩展图像:
my $image = Image::Magick->new;
open( IMAGE, $filename );
$image->Read( file => \*IMAGE );
close(IMAGE);
$image->Extent( gravity => 'Center', width => 150, height => 150, );
$image->Write( $outfile );
虽然图像被扩展到正确的大小,但它不在中间。我正确使用它吗?
更新:
我也尝试使用笨拙的版本:
$image->Set( Gravity => 'Center' );
但还是不行。我使用的是 6.5.8-10 版。
第二次更新:
在 PerlMagick 的更新日志中找到了这个:
2009-10-18 6.5.7-0 Cristy <quetzlzacatenango@image...>
* Interpret gravity properly for ExtentImage().
最佳答案
#Ok, you need to extent your image upto 100x100 and fill new area by transparent background:
($nx, $ny) = $image->Get('base-columns','base-rows');
$nnx = 50-$nx/2;
$nny = 50-$ny/2;
$image->Extent(geometry=>"100x100-$nnx-$nny", background=>"graya(0%, 0)");
#woohoo!
关于perl - 当我使用 Perl::Magick's Extent with Gravity 时,为什么我的图像不在中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2074288/