bash 使用 imagemagick 如何将图像分割成几个单独的图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9636350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using imagemagick how can i slice up an image into several separate images?
提问by jottr
Please consider following example:
请考虑以下示例:


The source image consists of 6 areas that need to be sliced up into 6 separate images.
源图像由 6 个区域组成,这些区域需要切成 6 个单独的图像。
How can I get the desired output using imagemagick. I tried to understand a possible solution presented in the imagemagick examples, but failed to transfer it to my specific problem.
如何使用 imagemagick 获得所需的输出。我试图理解 imagemagick示例中提出的可能解决方案,但未能将其转移到我的具体问题中。
What would be a way of solving this problem preferably in a one-liner? Since all the areas which i want to slice have the same size, but only differ in their offset, is there a way to somehow pass a preset area size, and then simply add the xy-offset for each area?
最好在单线中解决这个问题的方法是什么?由于我想要切片的所有区域都具有相同的大小,但只是它们的偏移量不同,有没有办法以某种方式传递预设的区域大小,然后简单地为每个区域添加 xy 偏移量?
回答by Devourant
If each area has the same amount of padding around it, you can use the @operator.
如果每个区域周围有填充相同数量的,可以使用的@运营商。
This cuts an image into 6 sections, 2 per row, with 40 pixels of horizontal padding and 20 pixels of vertical padding excluded from each section:
这将图像切割成 6 个部分,每行 2 个,每个部分排除 40 像素的水平填充和 20 像素的垂直填充:
convert image.png -crop 2x3-40-20@ +repage +adjoin tile-%d.jpg

