【问题标题】:how to batch resize and crop with imagemagick and mogrify如何使用 imagemagick 和 mogrify 批量调整大小和裁剪
【发布时间】:2019-12-20 12:49:04
【问题描述】:

我有一个包含数百个混合尺寸的 png 的目录。使用 imagemagick 和 mogrify 我想:

  1. 将图像调整为 512 像素 -- 如果宽度小于则为 512,如果高度小于则为 512
  2. 将更宽的尺寸裁剪为 512 以制作 512x512 的正方形

感谢任何帮助,花时间理解 imagemagick 文档。

【问题讨论】:

    标签: resize imagemagick batch-processing crop mogrify


    【解决方案1】:

    如果我正确理解了您的问题,并且您只想在图像的任一尺寸小于 512 时才调整大小,以便将其放大到 512x512 保留纵横比。并且您想要填充(而不是裁剪),以便结果恰好是 512x512。并且您只想处理 PNG。然后你可以在 Unix 的 ImageMagick 6 中这样做。

    create a new directory to hold the output, so that you do not overwrite
    
    cd to directory containing the images
    
    mogrify -format png -path path/to/new_directory -resize "512x512<" -background white -gravity center -extent 512x512 *.png
    


    如果使用 ImageMagick 7,请将 mogrify 更改为 magick mogrify

    【讨论】:

    • 我希望你不介意我的小编辑。我澄清了 mogrifymagick mogrify 是您在 shell/Terminal 中键入的命令,它们用反引号括起来。
    • 谢谢,马克。没问题
    • 啊,谢谢你的工作,它在中心裁剪了 512x512 的所有内容,但它没有先调整大小?不过谢谢!
    • 它只根据您的要求调整小于 512x512 的图像的大小。如果您只需要较大的图像,则将 。如果您希望它为所有图像调整大小,请删除 <.>
    猜你喜欢
    • 1970-01-01
    • 2012-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-11
    • 2018-09-22
    • 2015-12-04
    • 2012-11-10
    相关资源
    最近更新 更多