我必须从照片中创建无缝的方形图片。每张照片的分辨率为6000x4000,转换后的图像应为4000x4000px左右。我想在Linux机器上使用imagemagick从bash或perl脚本运行它。有没有人有一个简单的方法呢?
发布于 2016-11-28 18:29:13
让我们从这个600x400的图像开始:

现在,如果您想要原始图像的宽度和全高的中心400像素:
convert start.png -gravity center -extent 400x result.png

或者,如果你想要最右边的300像素:
convert start.png -gravity east -extent 300x result.png

或者,如果像你的问题一样,但缩小了10倍,你想从左边开始100px,取400px,你可以用偏移量裁剪:
convert start.png -crop 400x+100 result.png

备注:
我用以下命令制作了开始图像:
convert xc:cyan xc:magenta xc:yellow +append -resize 600x400\! start.png发布于 2016-11-16 07:13:40
Perl在这里。这将从位置0,0(左上角)开始将图像裁剪到400x400:
use warnings;
use strict;
use Image::Magick;
my $img = Image::Magick->new;
$img->Read('img.jpg');
print $img->Get('width') . " ";
print $img->Get('height') ."\n";
$img->Crop(geometry => '400x400+0+0');
$img->Write('img_new.jpg');
$img->Read('img_new.jpg');
print $img->Get('width') . " ";
print $img->Get('height') ."\n";输出:
4128 2322 # original
400 400 # newhttps://stackoverflow.com/questions/40621086
复制相似问题