代码之家  ›  专栏  ›  技术社区  ›  Thomi

如何编写一个bash脚本,使用image magick将图像分割成碎片?

  •  5
  • Thomi  · 技术社区  · 16 年前

    我有许多输入图像,其中包含多个较小的图像,所有这些图像都在一行中。所有包含的图像大小相同。例如,图像 input.png 480x48 48x48

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

    我能做的用户交互,但我没能得到 转换 进行实际切割。有人能提出一些建议吗?通过阅读手册页,我认为这应该奏效:

    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@

    有什么想法吗?

    2 回复  |  直到 12 年前
        1
  •  5
  •   Dennis Williamson    16 年前

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

    阅读更多 Tile Cropping, in ImageMagick documentation .

        2
  •  9
  •   Denilson Sá Maia    10 年前

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

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

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