删除图像的水平切片并通过周围区域从上方和下方填充其空白
原始图像和期望的结果
我有一批 PNG 图像,需要相同的自动图像处理:
- 中间部分(红色)应被完全消除,其空隙从上方/下方填充
- 顶部(蓝色)和中间部分(红色)始终具有相同的
- 高度底部(绿色)的高度可能会有所不同
如何通过免费的可脚本图像处理来实现此目的套房?
- 例如 ImageMagic 或 sips
Original Images & Desired Outcome
I have a batch of PNG images which need the same automated image processing:
- Middle part (red) shall get eliminated entirely and its void filled from above/below
- Top (blue) and middle part (red) always have the same height
- The bottom part (green) may vary in height
How do I achieve this with a free script-able image processing suite?
- Such as ImageMagic or sips
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ImageMagick -chop 正是
-chop 上的手册页:
同样方便的是对应函数 -splice:
剪掉不需要的红色行
→
convert in.png -chop x92+0+50 out-chopped.png
in。 png
是原始图像out-chopped.png
是期望的结果-chop x92+0+50
:从左上角的默认参考点(可以是更改为 -gravity) 位于 x +0px 和 y +50px(顶部蓝色之后)我们想要保留的部分)以全宽(因为在x
之前没有指定数字,因此它假定整个画布宽度)和 92px 的高度(有一些接缝,因此我添加了2px 剪切干净)剪掉不需要的红色部分 + 插入一个细分隔符行
→
→
如果你想在剪掉的地方插入一些分隔符,你可以使用
-splice
来实现。convert in.png -chop x92+0+50 -background black -splice x2+0+50 out-chopped-spliced-separator.png
-chop
上面已经解释-background
更改为black
,这适用于队列中的所有后续命令。-splice x2+0+50
从默认参考点左上角 X 0px 和 Y 50px 拼接成一行全宽(x
前面没有指定) )和 2px 高度。因为我们在上一步中将背景色设置为黑色,所以 2px 行填充为黑色。批处理
mogrify
为相应的输出文件保留每个输入文件的相同文件名。通常它会就地覆盖。但我们使用:-path
将输出文件写入目标目录../batch-done
*
考虑当前目录的所有文件通过 shell 通配符作为批处理的输入文件。-chop 上的Sources
ImageMagick -chop does just that
Man page on -chop:
Also handy is the counterpart function -splice:
Chop out the undesired red row
→
convert in.png -chop x92+0+50 out-chopped.png
in.png
is the original imageout-chopped.png
is the desired outcome-chop x92+0+50
: From the default reference point top left (could be changed with -gravity) at x +0px and y +50px (after the top blue part we want to keep) chop out the red segment at full width (because no number is specified before thex
and hence it assumes full canvas width) and at a height of 92px (had some seam, hence I added 2px to cut clean)Chop out the undesired red part + insert a thin separator row
→
→
If you want to insert some separator where you chopped out, you can achieve that with
-splice
.convert in.png -chop x92+0+50 -background black -splice x2+0+50 out-chopped-spliced-separator.png
-chop
already explained above-background
toblack
which applies to all later command in the queue.-splice x2+0+50
From the default reference point top-left at X 0px and Y 50px splice in a row of full width (nothin specified in front of thex
) and of 2px height. Because we have set the background color black in the previous step that 2px row is filled black.Batch processing
mogrify
keeps the same filename of each input file for the corresponding output file. Normally it overwrites in place. But we use:-path
to write the out files to target directory../batch-done
*
to consider all files of your current directory via shell globbing as the input files of your batch.Sources