【问题标题】:Create two sizes of an image using one ImageMagick command使用一个 ImageMagick 命令创建两种尺寸的图像
【发布时间】:2015-06-08 09:55:06
【问题描述】:

我正在使用 ImageMagick 生成大型 TIFF 图像的小尺寸 JPEG 版本。对于每个 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 x 5 个尺寸)。

那么,是否可以使用单个 ImageMagick 命令生成两个或多个不同大小的输出文件?

【问题讨论】:

    标签: image imagemagick image-resizing


    【解决方案1】:

    是的,可以使用-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
    

    在这种情况下,写入图像的顺序无关紧要。

    【讨论】:

    • 好像是用第一个尺寸来创建第二个尺寸而不是原来的。
    • 格伦的回答是正确的——我怀疑他只是先创建更大的图像,以便直接从全尺寸原件创建它,而不是试图增加已经缩小的较小输出图像的分辨率从而失去质量。
    【解决方案2】:

    这是一个使用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 上的换行符。

    【讨论】:

      猜你喜欢
      • 2020-04-01
      • 1970-01-01
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多