如何在保持宽高比和最大宽度和高度的同时在 ImageMagick 中批量调整图像大小?

How do I batch-resize images in ImageMagick while maintaining aspect ratio and a max width and height?

我有一个高分辨率图片文件夹。它是 JPG 和 24 位透明 PNG 的混合。我想按照以下规则批量生成缩略图:

我是 ImageMagick 的新手,不知道我需要 运行 什么命令才能达到这个结果。最终,这是一个 Jekyll 项目,但我很高兴能够通过命令行手动 运行 这个过程。

如有任何帮助,我们将不胜感激!

ImageMagick 命令行 mogrify 可能是您想要的并且可以做您需要的。它处理一个充满图像的文件夹。参见 https://imagemagick.org/Usage/basics/#mogrify and https://imagemagick.org/script/command-line-options.php#resize。该命令类似于以下内容:

Create a new directory to hold your output, say, thumbnails.
Change directory to your folder with the images

mogrify -path path_to/thumbnails -resize 488x220 *


该命令将处理您文件夹中的每个文件。如果您有其他格式,例如您不想处理的 txt 或其他图像,请修改命令以限制为 png 和 jpg,如下所示:

mogrify -path path_to/thumbnails -resize 488x220 *.png *.jpg


add *.PNG *.JPG *.jpeg *.JPEG to the end of the line,如果您的目录中的后缀有不同的大写和拼写。

其他编程语言有不同的 API。参见 https://imagemagick.org/script/sitemap.php#program-interfaces