简体   繁体   English

web 的有损图像压缩和透明度?

[英]Lossy image compression, plus transparency, for the web?

One advantage of PNG is full alpha transparency, which allows you to have smooth edges and shadows in in web designs. PNG 的一个优点是完全 alpha 透明度,它允许您在 web 设计中拥有平滑的边缘和阴影。 The main disadvantage is that it only supports lossless compression, which for complex images means a very large file size.主要缺点是它只支持无损压缩,这对于复杂的图像意味着非常大的文件大小。

JPEG on the other hand offers great compressibility for complex images, but no transparency.另一方面,JPEG 为复杂图像提供了很好的可压缩性,但没有透明度。

And finally, I've seen Flash elements ( example here ) with highly compressed images that also have smoothed edges and shadows.最后,我看到 Flash 元素(此处为示例)具有高度压缩的图像,这些图像也具有平滑的边缘和阴影。 I don't know much about Flash and have no idea how this is accomplished.我对 Flash 不太了解,也不知道这是如何实现的。 This is basically the effect I would like to be able to do - a large, complex image with transparent and/or shadowed edges.这基本上是我希望能够做到的效果 - 具有透明和/或阴影边缘的大型复杂图像。

My questions are:我的问题是:

How does lossy compression with transparency work in Flash? Flash 中的透明有损压缩如何工作?

Are there flash specific layering tricks being used here?这里是否使用了 flash 特定的分层技巧? Are the shadows generated or rasterized into the image as I would do with a PNG.阴影是否像我对 PNG 所做的那样生成或光栅化到图像中。

Are there any SWFs or SWF generating scripts that could replace a PNG image with a lossily compressed version?是否有任何 SWF 或 SWF 生成脚本可以用有损压缩版本替换 PNG 图像?

I'm thinking progressive enhancement to improve loading speed of certain design elements.我正在考虑逐步增强以提高某些设计元素的加载速度。 If this doesn't exist, would it be feasible to write it?如果这不存在,写它是否可行?

Are there any formats that allow lossy compression with transparency是否有任何格式允许透明的有损压缩

It's been hard for me to find specific info on this.我很难找到这方面的具体信息。 DjVu might be a candidate? DjVu 可能是候选人? Should we be pushing browser makers to support another format?我们是否应该推动浏览器制造商支持另一种格式?

Are there other solutions to this problem?这个问题还有其他解决方案吗?

Doing everything in Flash or accepting enormous file sizes are the current options.在 Flash 中执行所有操作或接受巨大的文件大小是当前的选项。 Some other possibilities:其他一些可能性:

  • SVG and canvas may be able to apply edges, but aren't supported by IE. SVG 和 canvas 可能能够应用边缘,但 IE 不支持。
  • You could cut up a PNG along scan lines and compress those with JPEG, leaving the edges as PNG.您可以沿扫描线切割 PNG 并使用 JPEG 压缩它们,将边缘保留为 PNG。 This would be nasty in source, but it would work in all browsers.这在源代码上会很讨厌,但它适用于所有浏览器。 Sounds like a fun project, I'll write it by the morning.听起来像一个有趣的项目,我会在早上写。 :) :)
  • You could write a lossy image filter that can decrease color complexity along the PNG algorithm's scan lines to improve compression within the PNG format.您可以编写一个有损图像过滤器,它可以降低 PNG 算法扫描线的颜色复杂性,以提高 PNG 格式的压缩率。 I just knew this had to exist, but I couldn't find it.我只知道它必须存在,但我找不到它。 Anyone know of this?有人知道吗?

Thanks for your help!谢谢你的帮助!

One advantage of PNG is full alpha transparency, which allows you to have smooth edges and shadows in in web designs. PNG 的一个优点是完全 alpha 透明度,它允许您在 web 设计中拥有平滑的边缘和阴影。 The main disadvantage is that it only supports lossless compression, which for complex images means a very large file size.主要缺点是它只支持无损压缩,这对于复杂的图像意味着非常大的文件大小。

You are wrong.你错了。 You can use PNG with lossy compression (8-bit indexed colors) and alpha transparency.您可以使用带有有损压缩(8 位索引颜色)和 alpha 透明度的 PNG。

I'm developing pngquant , which generates paletted PNGs with full alpha .我正在开发pngquant ,它会生成带有完整 alpha的调色板 PNG。

The conversion to palette is pretty close to being lossy compression and gives similarly good results — you can often reduce image sizes by 60-70% with little quality loss.向调色板的转换非常接近于有损压缩,并且提供了类似的良好结果——您通常可以将图像尺寸减小 60-70%,而几乎没有质量损失。

I've also created Mac GUI for it which includes lossy filter for PNGs (posterization with appropriately selected levels). I've also created Mac GUI for it which includes lossy filter for PNGs (posterization with appropriately selected levels). That technique reduces images by about 30%, but works with 24-bit images.该技术将图像减少了大约 30%,但适用于 24 位图像。

Are there flash specific layering tricks being used here?这里是否使用了 flash 特定的分层技巧?

Could be.可能。 It's possible to manipulate bitmaps in ActionScript, so you could take the Alpha layer from a simple transparent PNG with no colour data, and combine it with the pixel data from a JPEG.可以在 ActionScript 中操作位图,因此您可以从没有颜色数据的简单透明 PNG 中获取 Alpha 层,并将其与 JPEG 中的像素数据相结合。

Are there any formats that allow lossy compression with transparency是否有任何格式允许透明的有损压缩

Yes, JPEG 2000 and Microsoft's HD Photo .是的, JPEG 2000和 Microsoft 的高清照片 Don't hold your breath for browser support though!不过,不要屏住呼吸以获得浏览器支持!

You can use ming and create the flash on the fly at your backend, here is a sample in PHP that shows masking jpgs您可以使用ming并在后端动态创建 flash,这是 PHP 中的示例,显示屏蔽 jpg

If you're refering to the students popping up on the site that's done by masking.如果您指的是通过屏蔽完成的网站上弹出的学生。 To make a complex mask you'll either have to draw it yourself in Flash, or if you have Illustrator you can Live Trace your image to get a pretty good vector approximation of the outline.要制作一个复杂的蒙版,您要么必须自己在 Flash 中绘制它,要么如果您有 Illustrator,您可以实时跟踪您的图像以获得一个非常好的轮廓矢量近似值。 Flash has a trace bitmap function as well, but the Illustrator version is much more powerful. Flash 有一个跟踪 bitmap function 以及,但 Illustrator 版本更强大。

Flash CS4 allows you to apply filter effects like drop shadow and blur to MovieClips and text that are rendered at runtime. Flash CS4 允许您将阴影和模糊等滤镜效果应用于运行时渲染的 MovieClip 和文本。

So basically:所以基本上:

  1. Get image获取图像
  2. Get vector outline of image获取图像的矢量轮廓
  3. Place the vector outline on the layer above the image and apply the mask.将矢量轮廓放在图像上方的图层上并应用蒙版。 You should now be left with just your image with all the white space removed.你现在应该只剩下你的图像,所有的空白都被删除了。
  4. If you want a drop shadow copy the vector outline onto a layer below the JPEG, line it up with the mask and apply the drop shadow on that bottom layer in Properties>Filters.如果您想要阴影将矢量轮廓复制到 JPEG 下方的图层上,请将其与蒙版对齐,然后在“属性”>“过滤器”中将阴影应用到该底层。 Make sure it's a MovieClip or you wont be able to place a shadow on it.确保它是一个影片剪辑,否则您将无法在其上放置阴影。

If you need more clarification or you want an sample file then drop me an email at jcullinan (at) pinnaclegfx (dot) com如果您需要更多说明或想要一个示例文件,请在 jcullinan (at) pinnaclegfx (dot) com 给我一个 email

I see some interesting answers.我看到了一些有趣的答案。 Maybe I can add to that because I ran into the same issue.也许我可以补充一下,因为我遇到了同样的问题。

How does lossy compression with transparency work in Flash? Flash 中的透明有损压缩如何工作?

It works well, it's like a transparent jpg:)效果很好,就像是透明的jpg :)

Are there any SWFs or SWF generating scripts that could replace a PNG image with a lossily compressed version?是否有任何 SWF 或 SWF 生成脚本可以用有损压缩版本替换 PNG 图像?

Yes there are:是的,有:

Check out Durej's Images 2 SWFs and mr.doob's png2swf查看Durej 的 Images 2 SWFmr.doob 的 png2swf

Hope it helps.希望能帮助到你。 Good luck!祝你好运!

You can use a JPEG and a mask.您可以使用 JPEG 和蒙版。 The mask could be bitmap (should compress losslessly as PNG or GIF quite well), or a vector.掩码可以是 bitmap (应该很好地无损压缩为 PNG 或 GIF),或矢量。

For most web use, package these together as an SVG - http://peterhrynkow.com/how-to-compress-a-png-like-a-jpeg/ For most web use, package these together as an SVG - http://peterhrynkow.com/how-to-compress-a-png-like-a-jpeg/

For some applications, you might use them separately.对于某些应用程序,您可能会单独使用它们。 It allows you to re-use masks, when you have the same shape but a different texture.当您具有相同的形状但不同的纹理时,它允许您重复使用蒙版。 It also might just be better for your workflow or framework of choice.它也可能对您选择的工作流程或框架更好。

PNG does support lossy compression, but it's terrible compared to JPEG. PNG确实支持有损压缩,但与JPEG相比它很糟糕。 For example, here's a section of an image that has been compressed to 100kb with both PNG and JPEG:例如,下面是使用 PNG 和 JPEG 压缩到 100kb 的图像的一部分:

PNG 与 JPEG 有损压缩到 100kb

So you can see that PNG files don't handle subtle gradients well.所以你可以看到PNG文件不能很好地处理细微的渐变。 They're not designed to do that.他们不是为此而设计的。

It looks like the best bet in the near-term is to wait for WebP support , which is actually available in all major browsers already, but only in recent versions of Safari (as of writing).看起来近期最好的选择是等待WebP 支持,这实际上已经在所有主要浏览器中都可用,但仅在 Safari 的最新版本中(截至撰写时)。

The new AVIF is also a contender in the lossy-transparency space, but it is only supported in Chrome, Opera and Firefox as of writing (Firefox 86 and later).新的AVIF也是有损透明空间的竞争者,但在撰写本文时(Firefox 86 及更高版本)仅支持 Chrome、Opera 和 Firefox Hopefully other browsers add support for this soon, because it has very good perceptual characteristics for high compression ratios.希望其他浏览器尽快添加对此的支持,因为它对于高压缩比具有非常好的感知特性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM