ImageMagick从透明png底部修剪底部

发布于 2025-02-12 19:18:44 字数 2617 浏览 1 评论 0 原文

我正在尝试编写一个成像命令,以从透明的PNG底部修剪透明像素。 我找到了这些命令 并修改了它们以使其倒下。但是,输出不符合预期。

有了一些试验和错误,我发现该命令似乎正在生成最小高度的图像。如果设计太高,则在下面留下透明的像素。但是,没有什么能成为导致命令的元素?

我包括了我修剪的3个文件,以及以下命令的3个结果 生成:

convert \( ORIGINAL.png -bordercolor none -border 1x0 \) -size 1x1 xc:black -gravity west -composite -size 1x1 xc:black -gravity east -composite -size 1x1 xc:black -gravity north -composite -fuzz 10% -trim +repage -bordercolor white -shave 1x0 TRIMMED.png

convert \( ORIGINAL2.png -bordercolor none -border 1x0 \) -size 1x1 xc:black -gravity west -composite -size 1x1 xc:black -gravity east -composite -size 1x1 xc:black -gravity north -composite -fuzz 10% -trim +repage -bordercolor white -shave 1x0 TRIMMED2.png

convert \( ORIGINAL3.png -bordercolor none -border 1x0 \) -size 1x1 xc:black -gravity west -composite -size 1x1 xc:black -gravity east -composite -size 1x1 xc:black -gravity north -composite -fuzz 10% -trim +repage -bordercolor white -shave 1x0 TRIMMED3.png

如果有人可以解释我在这个高度问题方面所缺少的东西,这将不胜感激。

这是3个原始文件和3个结果,显示结果如何随着原始文件的变化而变化。

这就是我试图获得的方法 - 从图像底部删除空白空间。目前,如果图像太高,我仍然不想空间,我仍然在下面获得空间(请参阅最后一个结果,右下)

- 下面是原始文件,如果有人想在其设置等上尝试它, ---

“我的原始尝试”

I am attempting to write an imagemagick command to trim the transparent pixels from the bottom of a transparent PNG. I found these commands and modified them to take off just the bottom. However the output is not as expected.

With some trial and error I've identified that the command appears to be generating an image of a minimum height. If the design is too high it leaves transparent pixels underneath. But nothing jumps out at me as being the element of the command that causes that?

I've included my 3 files that I trimmed and the 3 results that the following command(s)
generates:

convert \( ORIGINAL.png -bordercolor none -border 1x0 \) -size 1x1 xc:black -gravity west -composite -size 1x1 xc:black -gravity east -composite -size 1x1 xc:black -gravity north -composite -fuzz 10% -trim +repage -bordercolor white -shave 1x0 TRIMMED.png

convert \( ORIGINAL2.png -bordercolor none -border 1x0 \) -size 1x1 xc:black -gravity west -composite -size 1x1 xc:black -gravity east -composite -size 1x1 xc:black -gravity north -composite -fuzz 10% -trim +repage -bordercolor white -shave 1x0 TRIMMED2.png

convert \( ORIGINAL3.png -bordercolor none -border 1x0 \) -size 1x1 xc:black -gravity west -composite -size 1x1 xc:black -gravity east -composite -size 1x1 xc:black -gravity north -composite -fuzz 10% -trim +repage -bordercolor white -shave 1x0 TRIMMED3.png

If someone could please explain what I am missing in terms of this height issue that would be really appreciated.


These are the 3 ORIGINAL files and the 3 outcomes showing how the outcome changes with the original file changes.


This is what I am trying to acheive - delete the empty space from the bottom of the image. I want no space after the image at the moment if it is too high I still get space underneath (see the last outcome, bottom right)

---- BELOW ARE JUST THE ORIGINAL FILES IF ANYONE WANTED TO TRY IT ON THEIR SETUP ETC ----

My original attempt
Here you can see lots of space

My second attempt
Trimmed right to the bottom

My 3rd attempt
Small gap leading me to beleive there is some minimum height coming from somewhere

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

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

发布评论

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

评论(1

围归者 2025-02-19 19:18:44

如果您要删除“ -trim”将删除的内容,但仅从图像的底部边缘中删除,则该命令应为您提供结果...

convert input.png -background none -set page %[@] \
   -set option:distort:viewport %[w]x%[fx:page.y+page.height] \
   +repage -distort SRT 0 result.png                

首先设置一些包含“ - ”结果的变量。修剪操作,但实际上没有删除任何东西。然后,它使用这些变量来计算输出视口的三个后尺寸。然后,它使用no-op“ -distort”有效地将图像裁剪到计算的输出尺寸上,仅将多余的透明像素朝向底部。

If you're trying to remove what a "-trim" would remove, but only from the bottom edge of an image, this command should give you that result...

convert input.png -background none -set page %[@] \
   -set option:distort:viewport %[w]x%[fx:page.y+page.height] \
   +repage -distort SRT 0 result.png                

It starts by setting some variables that contain the results of a "-trim" operation, but without actually removing anything. Then it uses those variables to calculate the after-trim dimensions for the output viewport. Then it uses a no-op "-distort" to effectively crop the image to the calculated output dimensions, removing only the excess transparent pixels toward the bottom.

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