如何使用GraphicsMagick裁剪多张图片

4
根据GraphicsMagick手册,我可以使用不带偏移量的-crop来从图像创建多个瓦片:

如果省略x和y偏移量,则会生成一组覆盖整个输入图像的指定几何体的瓦片。 如果指定的几何体超出输入图像的尺寸,则右侧和底部的瓦片较小。

因此,我在Linux下运行了以下命令:

gm convert -crop 256x256 input.png tile      # => a single file called tile
gm convert -crop 256x256 input.png tile.png  # => a single file called tile.png

如何指定输出,以便创建多个图像?

1个回答

5
gm convert -crop 256x256 input.png +adjoin tile%04d.png
+adjoin 是关键。 从手册的文件和格式部分:

Single images are written with the filename you specify. However, multi-part images (e.g., a multi-page PostScript document with +adjoin specified) may be written with the scene number included as part of the filename. In order to include the scene number in the filename, it is necessary to include a printf-style %d format specification in the file name and use the +adjoin option. For example,

 image%02d.miff

writes files image00.miff, image01.miff, etc. Only a single specification is allowed within an output filename. If more than one specification is present, it will be ignored. It is best to embed the scene number in the base part of the file name, not in the extension, because the extension will not be a recognizeable image type.

以下是与adjoin相关的内容:

Use +adjoin to force saving multiple frames to multiple numbered files. If +adjoin is used, then the output filename must include a printf style formatting specification for the numeric part of the filename. For example,

image%02d.miff

为什么文档中没有明确说明这一点?感谢您回答这个问题。 - Steven Lu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接