5

我有许多包含多个较小图像的输入图像,它们都在一行中。所有包含的图像大小相同。因此,例如,图像input.png可能是480x48并且包含 10 个48x48图像,都在一行中。

使用 imagemagickconvert工具(或默认 imagemagick 套件提供的任何其他工具),我想编写一个 bash 脚本,该脚本获取输入图像、要剪切的图像数量,然后将它们全部剪切成单独的图像。

我可以进行用户交互,但我无法进行convert实际切割。任何人都可以提出一些建议吗?通过阅读手册页,我认为这应该可行:

convert 'input.png[0x0+48+48]' output.png

但我收到一个错误:

转换:缓存 tb_icons_l.png' @ magick/cache.c/OpenCache/3572. convert: No IDATs written into file 1.png'@coders/png.c/PNGErrorHandler/1391 中没有定义像素。

有任何想法吗?

4

2 回答 2

9

我会这样做:

convert input.png -crop 48x48  +repage  +adjoin  output_%02d.gif

在 ImageMagick 文档中的 Tile Cropping 中阅读更多信息。

于 2009-09-29T10:01:05.913 回答
5

我相信你已经交换了位置和大小。尝试:

convert 'input.png[48x48+0+0]' output.png

第三张图片是:

convert 'input.png[48x48+96+0]' output.png

或者

convert 'input.png[48x48+0+96]' output.png
于 2009-09-29T10:10:31.920 回答