删除图像的水平切片并通过周围区域从上方和下方填充其空白

发布于 2025-01-14 00:21:37 字数 298 浏览 2 评论 0原文

原始图像和期望的结果

我有一批 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

Original and Desired Outcome

How do I achieve this with a free script-able image processing suite?

  • Such as ImageMagic or sips

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绅士风度i 2025-01-21 00:21:37

ImageMagick -chop 正是

-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 -chop x92+0+50 -background black -splice x2+0+50 *
  • mogrify 为相应的输出文件保留每个输入文件的相同文件名。通常它会就地覆盖。但我们使用:
  • -path 将输出文件写入目标目录 ../batch-done
  • * 考虑当前目录的所有文件通过 shell 通配符作为批处理的输入文件。

-chop 上的Sources

ImageMagick -chop does just that

Man page on -chop:

The -chop option removes entire rows and columns, and moves the remaining corner blocks leftward and upward to close the gaps.

Also handy is the counterpart function -splice:

This will add rows and columns of the current -background color into the given image

Chop out the undesired red row



convert in.png -chop x92+0+50 out-chopped.png

  • in.png is the original image
  • out-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 the x 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
  • as the next processing step we change -background to black 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 the x) 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 -path ../batch-done -chop x92+0+50 -background black -splice x2+0+50 *
  • 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文