仅在一个特定的 JPEG 文件上将 PNG 合成到 JPEG 失败(颜色全部渲染为黑色)

发布于 2025-01-02 01:29:05 字数 459 浏览 3 评论 0原文

我正在构建一个应用程序,它使用 Ruby+RMagick 将 PNG 图像合成到各种 JPEG 背景上。一切正常,但是我们发现了一个特定的 JPEG 背景,其中 PNG 被合成为黑点。 PNG 透明度受到尊重; “斑点”的形状是正确的,但颜色正在丢失并变成黑色。

我尝试了很多 JPEG,试图找到另一个产生相同结果的 JPEG,但(到目前为止)都失败了。

我怀疑这可能与相关 JPEG 文件的位深度或其他一些参数有关。我一直在互联网上搜索,寻找一个可以分析这个 JPEG 并告诉我所有可能相关的参数的工具,但还没有找到任何东西。

  1. 你有遇到过这样的事情吗?原因是什么?
  2. 根据您对 JPEG 格式的了解,是否还有其他可能相关的参数?
  3. 你知道有什么工具可以分析 JPEG 文件,并告诉我位深度和其他参数吗?或者,如果我在十六进制编辑器中打开 JPEG,你能告诉我如何找到这些信息吗?

I'm building an application which uses Ruby+RMagick to composite PNG images onto various JPEG backgrounds. Everything is working, but we have found one particular JPEG background for which the PNG is composited as a black spot. PNG transparency is respected; the shape of the "spot" is correct, but the colors are being lost and becoming black.

I have tried many JPEGs to try to find another which yields the same result, but (so far) have failed.

I suspect that it may have something to do with the bit depth or some other parameter of the JPEG file in question. I have been searching the Internet, looking for a tool which can analyze this JPEG and tell me all the parameters which might be relevant, but haven't found anything yet.

  1. Has anything like this ever happened to you? What was the cause?
  2. Based on your knowledge of the JPEG format, are there any other parameters which might be relevant?
  3. Do you know of any tool which can analyze JPEG files, and tell me the bit depth and other parameters? Or if I open the JPEG in a hex editor, can you tell me how to find this information?

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

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

发布评论

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

评论(1

旧街凉风 2025-01-09 01:29:05

我仍然没有发现复合操作无法正常工作的那张 JPG 有什么特别之处,但我使用以下代码解决了它:

back  = Magick::Image.from_blob(jpg_data).first
png   = Magick::Image.from_blob(png_data).first
page1 = Magick::Image.new(back.columns, back.rows)
page1.composite!(back, 0, 0, Magick::OverCompositeOp)
page1.composite!(png, png_x, png_y, Magick::OverCompositeOp)

而不是:

back  = Magick::Image.from_blob(jpg_data).first
png   = Magick::Image.from_blob(png_data).first
page1 = back.composite(png, png_x, png_y, Magick::OverCompositeOp)

I still haven't found what is special about that one JPG which the composite operation doesn't work correctly on, but I worked around it using this code:

back  = Magick::Image.from_blob(jpg_data).first
png   = Magick::Image.from_blob(png_data).first
page1 = Magick::Image.new(back.columns, back.rows)
page1.composite!(back, 0, 0, Magick::OverCompositeOp)
page1.composite!(png, png_x, png_y, Magick::OverCompositeOp)

Rather than:

back  = Magick::Image.from_blob(jpg_data).first
png   = Magick::Image.from_blob(png_data).first
page1 = back.composite(png, png_x, png_y, Magick::OverCompositeOp)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文