如何将图像列表中的图像调整为相同大小
How to resize images in the imagelist to the same size
我想使用 ImageMagick 对图像应用蒙版。但是由于图像和蒙版的大小不同,我想 stretch/scale 蒙版以适合图像。
通常输入图像为 2000x500px,但也可以为 1000x500px 或其他,掩码为 400x200px。
因此,如果我知道输入图像始终为 2000x500px,我可以这样做:
# Resize all images in the list to 2000x500
convert inputfile.png mask.png -resize 2000x500\! \
-compose over -composite \
outputfile.png
或
# Resize only the mask to 2000x500
convert inputfile.png \
\( mask.png -resize 2000x500\! \) \
-compose over -composite \
outputfile.png
但我的问题是我不知道输入文件的大小!那么如何将蒙版调整为与列表中第一张图像相同的大小?
使用 ImageMagick,您可以使用“-distort SRT”的缩放功能调整蒙版的大小以匹配输入图像的尺寸。示例命令可能看起来像这样...
convert input.png mask.png \
-set option:distort:viewport %[fx:u.w]x%[fx:u.h] \
-distort SRT "0,0 %[fx:u.w/s.w],%[fx:u.h/s.h] 0 0,0" \
-composite result.png
将视口设置为输入图像的尺寸,然后缩放两个图像以适合该视口。输入图像大小当然不会改变,因为它已缩放为 1/1。
我想使用 ImageMagick 对图像应用蒙版。但是由于图像和蒙版的大小不同,我想 stretch/scale 蒙版以适合图像。
通常输入图像为 2000x500px,但也可以为 1000x500px 或其他,掩码为 400x200px。
因此,如果我知道输入图像始终为 2000x500px,我可以这样做:
# Resize all images in the list to 2000x500
convert inputfile.png mask.png -resize 2000x500\! \
-compose over -composite \
outputfile.png
或
# Resize only the mask to 2000x500
convert inputfile.png \
\( mask.png -resize 2000x500\! \) \
-compose over -composite \
outputfile.png
但我的问题是我不知道输入文件的大小!那么如何将蒙版调整为与列表中第一张图像相同的大小?
使用 ImageMagick,您可以使用“-distort SRT”的缩放功能调整蒙版的大小以匹配输入图像的尺寸。示例命令可能看起来像这样...
convert input.png mask.png \
-set option:distort:viewport %[fx:u.w]x%[fx:u.h] \
-distort SRT "0,0 %[fx:u.w/s.w],%[fx:u.h/s.h] 0 0,0" \
-composite result.png
将视口设置为输入图像的尺寸,然后缩放两个图像以适合该视口。输入图像大小当然不会改变,因为它已缩放为 1/1。