我正在使用ImageMagick生成小尺寸JPEG版本的大型TIFF图像。对于每个TIFF图像,我必须生成两个较小的JPEG版本。
我目前正在使用两个convert
命令:
convert.exe 4096-by-3072px-120mb.tif -resize "1024x>" -strip -interlace Plane 1024px-wide-for-web.jpg
convert.exe 4096-by-3072px-120mb.tif -resize "1600x>" -strip -interlace Plane 1600px-wide-for-web.jpg
将TIFF逐个转换为JPEG需要花费太多时间。当每个图像通过网络加载并处理两次时,这种方法效率低下。当我计划为每个TIFF创建更多尺寸时,它会变得更糟(想想10,000个TIFF×5个尺寸)。
那么,是否可以使用单个ImageMagick命令生成两个或更多不同大小的输出文件?
是的,可以使用-write
选项:
convert 4096-by-3072px-120mb.tif -resize "1600x>" -strip -interlace Plane \
-write 1600px-wide-for-web.jpg -resize "1024x>" 1024px-wide-for-web.jpg
将输入图像重新缩放为1600像素宽,将其写出,然后将结果重新缩放为1024像素宽并写入。以大小的降序编写图像非常重要,以避免由于缩放到较小的尺寸而导致质量下降,然后再回到较大的尺寸。
如果您希望从输入图像重新缩放两个图像,请使用+clone
选项:
convert 4096-by-3072px-120mb.tif -strip -interlace Plane \
\( +clone -resize "1024x>" -write 1024px-wide-for-web.jpg +delete \) \
-resize "1600x>" 1600px-wide-for-web.jpg
在这种情况下,写入图像的顺序无关紧要。
这是一个使用memory program register的备用命令:
magick.exe 4096-by-3072px-120mb.tif -write mpr:main +delete ^
mpr:main -resize "1024x>" -quality 80 -interlace Plane -strip -write 1024px-wide-for-web.jpg +delete ^
mpr:main -resize "1280x>" -quality 80 -interlace Plane -strip -write 1280px-wide-for-web.jpg +delete ^
mpr:main -resize "1600x>" -quality 80 -interlace Plane -strip -write 1600px-wide-for-web.jpg +delete ^
mpr:main -resize "2048x>" -quality 80 -interlace Plane -strip 2048px-wide-for-web.jpg
经过测试:
注意:^
是Windows上的行继续符。