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

Tho*_*omi 5 linux bash imagemagick

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

使用imagemagick convert工具(或defaul 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中定义的像素 .

有任何想法吗?

小智 9

我会那样做:

convert input.png -crop 48x48  +repage  +adjoin  output_%02d.gif
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅ImageMagick文档中的Tile Cropping.


Pau*_*ce. 5

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

convert 'input.png[48x48+0+0]' output.png
Run Code Online (Sandbox Code Playgroud)

第三张图片是:

convert 'input.png[48x48+96+0]' output.png
Run Code Online (Sandbox Code Playgroud)

要么

convert 'input.png[48x48+0+96]' output.png
Run Code Online (Sandbox Code Playgroud)