JPEG 透明度

发布于 2024-12-02 01:43:30 字数 113 浏览 6 评论 0原文

JPEG 的尺寸比 PNG 小。所以,我想如果我可以用一些代码使 JPEG 文件中的特定区域透明,也许我可以节省一些字节。

那么有人知道如何使用 PHP 或 JavaScript 来实现这一点吗?

JPEGs are smaller in size than PNGs. So, I thought that if I can make a specific region in a JPEG-file transparent, with some code, maybe I can save some bytes.

So does anyone know how to achieve this with for example PHP or JavaScript?

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

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

发布评论

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

评论(5

无妨# 2024-12-09 01:43:30

不,你不能这样做。 JPG 不支持 Alpha 通道,也无法将某些颜色指定为透明(GIF 样式)。

No. You can't do this. JPGs do not support alpha channels and have no capacity to designate certain colors as transparent either (GIF-style).

旧情别恋 2024-12-09 01:43:30

这有几个问题,所有这些问题都与 JPEG 是一种有损压缩格式有关。 JPEG 格式针对自然图像进行了优化,锐利的边缘会变得模糊。如果您希望特定像素应具有值 #d67fff,则不能保证在颜色转换、FDCT、量化、IDCT 和颜色转换之后,该像素仍具有该值。该像素值也很有可能出现在您不想要的区域。

There's several issues with this, all of them have to do with that JPEG is a lossy compression format. The JPEG format is optimized for natural images and sharp edges will get blurred. If you intend that a specific pixel should have the value #d67fff there's no guarantee that after color conversion, FDCT, quantization, IDCT and color conversion, the pixel still will have that value. There's also a strong possibility that that pixel value will occur in areas that you don't want.

清晨说晚安 2024-12-09 01:43:30

否。JPEG 不支持透明度并且不太可能在任何时候都支持透明度
很快。 http://www.faqs.org/faqs/jpeg-faq /part1/section-12.html

No. JPEG does not support transparency and is not likely to do so any time
soon. http://www.faqs.org/faqs/jpeg-faq/part1/section-12.html

や莫失莫忘 2024-12-09 01:43:30

你不能这样做,客户端渲染图像并且不知道你希望它将该颜色视为透明(加上 jpeg 上的各种压缩方法无论如何都不能很好地处理透明度)。

我相信你可以使用 8 位自定义托盘 png,应该可以节省你很多空间。否则,24 位 PNG 是您唯一的高色彩选择。

You cannot do that, the client renders the image and doesn't know that you want it to treat that color as transparent (plus various compression methods on jpeg wouldn't work well with transparencies anyway).

I believe you can go with an 8-bit custom-pallet png, should save you a lot of space. Otherwise 24-bit PNG is your only high color option.

分開簡單 2024-12-09 01:43:30

您可以将图像转换为 SVG,其中包含 JPEG 形式的颜色信息和灰度蒙版形式的 Alpha 通道。这是我编写的一个工具https://github.com/igrmk/transpeg

You can convert your image to SVG containing a color information as JPEG and an alpha channel as grayscale mask. Here is a tool I wrote to do it https://github.com/igrmk/transpeg

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