将所有不透明像素转换为白色,保持透明度

发布于 2025-01-16 11:03:37 字数 735 浏览 3 评论 0原文

我有一堆 png 绘图,透明背景上的颜色和 Alpha 略有不同。

我想将非完全透明的像素转换为白色,保留局部 Alpha。在 Photoshop 中,我可以通过单击“锁定透明像素”图标,然后用白色填充整个图像来完成此操作。

我想自动化这个过程,并考虑在 Ubuntu 中使用 ImageMagick(在我的 Windows 10 的 WSL 上运行;convert -version 是 6.9.10。)

我已经用谷歌搜索了一段时间但没有运气,所以远的。找到这个答案,但它对我不起作用,它会出现以下错误并生成全白图像:

convert-im6.q16: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG `out.png' @ warning/png.c/MagickPNGWarningHandler/1667.

在其他地方,我发现 -strip 标志可以抑制此警告,但输出仍然是全白图像。

有趣的是,如果我指定非白色,结果几乎就是我需要的,当然颜色不是白色的。 (例如转换original.png -fill Yellow -colorize 100 out.png

I have a bunch of png drawings with slightly varying colors and alphas on a transparent background.

I want to convert the non-fully transparent pixels to white, keeping the local alpha. In Photoshop I can do this by clicking the "Lock transparent pixels" icon, then filling the entire image with white.

I'd like to automate this process and thought of using ImageMagick in Ubuntu (running on my Windows 10's WSL; convert -version is 6.9.10.)

I have been googling for a while without luck, so far. Found this SO answer, but it's not working for me, it bails out with the following error and produces an all-white image:

convert-im6.q16: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG `out.png' @ warning/png.c/MagickPNGWarningHandler/1667.

Elsewhere I found that the -strip flag can suppress this warning, however the output is still an all-white image.

Interestingly, if I specify a non-white color, the result is almost what I need, except of course the colors won't be white. (e.g. convert original.png -fill yellow -colorize 100 out.png)

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

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

发布评论

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

评论(2

歌枕肩 2025-01-23 11:03:37

也许这就是您在 ImageMagick 6 中想要的。使用 -fill 和 +opaque。

透明图片:

“在此处输入图像描述"

convert logot.png -fill white +opaque none logot_white.png

在此处输入图像描述

您必须下载每个图像才能看到透明的图像,因为该论坛使用白色背景颜色。

如果在 Imagemagick 7 上,将“convert”更改为“magick”

Perhaps this is what you want in ImageMagick 6. Use -fill and +opaque.

Transparent Image:

enter image description here

convert logot.png -fill white +opaque none logot_white.png

enter image description here

You will have to download each image to see what is transparent, since this forum uses a white background color.

If on Imagemagick 7, change "convert" to "magick"

鹤舞 2025-01-23 11:03:37

这是真实的 PEBKAC 情况。我只需要 -strip 标志,因为我认为是全白的图像实际上被正确地绘制为白色,并保留了原始透明度数据,只有图像缩略图在我的计算机上错误地生成了。

This was a true PEBKAC situation. I only needed the -strip flag, because what I thought to be all-white images were in fact correctly painted to white with their original transparency data preserved, only the image thumbnails were incorrectly generated on my computer.

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