网络漫画的图像压缩
可能和这里的很多人一样,我读过一些网络漫画。 Drowtales 是我的最爱,但这不是重点。
很长一段时间以来,一个想法一直困扰着我:网络漫画是画出来的图画。 它们不是照片。 应该有很多冗余(更少的颜色、更平坦的彩色区域等),因此它们应该能够以相当高的速率轻松压缩,同时仍然保持无损质量。 尽管如此,压缩它们的最佳工具似乎仍然是旧的有损 JPEG。
为何如此? 难道就没有更好的东西被发明了吗? 我不是数据压缩方面的专家,所以我自己寻找更好算法的微薄尝试是徒劳的。 我能找到的最好的是 Pngcrush,但它在压缩方面仍然远远落后于 JPEG。
我想听听专家对此的意见。 我的这个想法是不是愚蠢且注定要失败? 或者人们是否已经发现或者我可以研究某种方法?
当然,这是出于减少加载时间的自私愿望。 :)
补充:有些人似乎没有抓住重点,所以我会澄清:
网络漫画图像应该有很多冗余,所以它们应该很容易压缩。 是否无法以某种方式压缩它们,使它们既无损又小于 JPEG?或者至少比 JPEG 更好地压缩它们,同时仍保持质量。
由于它们将用于网络,专用压缩器仍可能会发出 PNG 或 JPEG - 只是使用修改后的算法进行压缩以获得更好的结果。
As probably many people around here I read a few webcomics. Drowtales is my favorite, but that's besides the point.
For a long time a thought has been nagging me at the back of my head: webcomics are drawn pictures. They are not photographs. There should be a lot of redundancy (less colors, more flat colored areas, etc.) and thus they should be easily compressible at quite high rates while still maintaining lossless quality. Still it seems that the best tool to compress them is the same old lossy JPEG.
How so? Are there not better things invented? I'm not an expert in data compression, so my own meager attempts at finding some better algorithm have been fruitless. Best I could find was Pngcrush, but it still is way behind JPEG in terms of compression.
I would like to hear an expert opinion on this. Is this idea of mine foolish and doomed to failure? Or is there perhaps some way that people have found or that I could look into?
This, of course, comes from the selfish desire to decrease load times. :)
Added: Some people seem to miss the point, so I'll clarify:
Webcomic images should have a lot of redundancy in them so they should be easily compressible. Is it not possible to somehow compress them so that they would be both lossless AND smaller than JPEG? Or at the very least compress them better than JPEG while still retaining the quality.
Since they would be for web the specialized compressor should still probably emit PNG or JPEG - just compressed with a modified algorithm for better results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
毫无疑问,这是外观和性能之间的平衡行为。 除非专门针对漫画使用自定义压缩算法,否则我认为您能做的最好的事情就是尝试 JPEG 压缩级别,直到获得一个合理的大小,但对于特定漫画来说仍然看起来不错的压缩级别。
来自 lbrandy.com
No question, it's a balancing act between appearance and performance. Barring a custom compression algorithm specifically for comics, I think the best you can do is experiment with JPEG compression levels until you get one that's a reasonable size, but still looks good for the particular comic.
From lbrandy.com
漫画的问题在于使用了大量的渐变着色。 例如,当使用 Photoshop 在计算机上为漫画着色时,一种常见的技术是首先像您提到的那样,用纯色遮挡区域。 然而,这些实体区域随后使用各种技术进行细化,从使用喷枪工具的手触摸到叠加渐变填充、闪避和燃烧工具等。
结果是一个更像自然图像的图像 - 这就是漫画艺术家正在努力的目标当然,因此使用有损算法(例如 JPEG 使用的算法)可以更好地压缩。
The problem with comics is that a lot of graduated colouring is used. A common technique when colouring a comic on computer using Photoshop, for example, is to start by blocking out areas in solid colour as you mentioned. However, these solid areas are then refined using various techniques, from hand touching using airbrush tools to overlaying graduated fills, dodging and burning tools, etc.
The result is an image which is more like a natural image - which is what comic artists are striving for of course - and thus it compresses better with a lossy algorithm such as that used by JPEG.
一种完全不同的方法是使用 SVG 等矢量格式渲染漫画图像。 这将捕获绘图的本质(此处填充、此处圆弧、此处线条等),而无需尝试对结果图像进行光栅压缩。
A completely different approach would be to render the comic images using a vector format like SVG. That would capture the essence of the drawing (fill here, arc here, line here, etc) without having to try to raster-compress the resulting images.
我的数据无法证实您的假设。我的最喜欢的网络漫画已经以 PNG 形式分发。 使用默认压缩质量将 167K PNG 文件转换为 JPEG 会生成 199K JPEG 文件。 收支平衡介于
-quality 60
和-quality 65
之间,这对于 JPEG 来说是相当低的质量。 因此,可疑内容已经被无损压缩并且比 JPEG 小。Your assumptions aren't borne out by my data. My favorite webcomic is already distributed as PNG. Converting a 167K PNG file to JPEG using the default compression quality yields a 199K JPEG file. Break-even is somewhere between
-quality 60
and-quality 65
, which is quite a low quality for a JPEG. So, Questionable Content is already compressed lossless and smaller than JPEG.我在制作用于网络的图像时学到了一些东西 -
jpegtran -optimise
- 它可以无损地重新压缩它们,并且可以将压缩不良的图像减少几个百分点。pngnq
运行 PNG 文件(使它们成为 8 位),然后通过optipng -i0
(重新压缩并删除任何隔行扫描)。 我知道你说过你不喜欢有损,但 pngnq 在将图像转换为调色板方面做得非常好 - 最好的办法就是自己尝试一下,看看输出是否足够好。A few things I've picked up on doing images for web use -
jpegtran -optimise
on JPEGs - it recompresses them losslessly and can shave a good few percent off poorly compressed images.pngnq
(make them 8 bit) and thenoptipng -i0
(recompress and remove any interlacing). I know you said you don't like lossy, but pngnq does an amazingly good job of converting images to a palette - best thing to do is try it yourself and see if the output is good enough.在某些情况下,JPEG 图像会比 PNG 图像大。
例如,如果图像非常简单,PNG 最终可能会更好地压缩图像并提供更好的图像质量。
下面是一些 Java 代码的示例:
上面的代码生成尺寸为 256 x 256 像素的图像,并在“X”上的窗体中绘制两条相交的对角线。
256 x 256 图像用于将图像大小保持为 8 的倍数,如 JPEG 压缩 对图像的 8 x 8 像素部分执行2D DCT 变换。 通过保持图像大小和线条位置在 8 x 8 像素部分内对齐,它将减少 压缩伪影并提高图像质量。
(选择 256 x 256 是经验性的——我一开始使用 100 x 100 并注意到 JPEG 图像很糟糕,所以我尝试了 64 x 64,它看起来更好,所以我将其放大以模拟更真实的图像尺寸。)
绘制图像后,程序生成 JPEG 文件和 PNG 文件。 (Java ImageIO 库 使用默认压缩比
0.75f
来保证 JPEG 的压缩质量。)结果:
从图像本身来看,JPEG 有一点伪影,但不是很严重。直到我用图像编辑器放大之前才注意到。 当然,PNG 图像是无损的,因此它是原始图像的精确表示。
总而言之,PNG 或 JPEG 的图像是否较小实际上取决于源 - 在某些情况下,JPEG 可能比 PNG 大,但 PNG 的质量可能更好。 当然,实际上,对于给定图像,PNG 通常会比 JPEG 大。
Under certain circumstances, JPEG images will be larger than PNG images.
For example, in cases where there is a very simple image, PNG may end up compressing the image better and giving better image quality.
Here's an example with some Java code:
The above code produces an image with the dimensions of 256 x 256 pixels, and draws two intersecting diagonal lines in the form on an "X".
The 256 x 256 image was used to keep the image size to an multiple of 8, as JPEG compression performs a 2D DCT transform on 8 x 8 pixel sections of the image. By keeping the image size and location of the line to align within the 8 x 8 pixel section, it will reduce the amount of compression artifacts and improve the quality of the image.
(Choosing 256 x 256 was empirical -- I at first used 100 x 100 and noticed that the JPEG image was horrible, so I tried 64 x 64 and it looked better, so I made it larger to simulate a more realistic image size.)
After drawing the image, the program generate a JPEG file and a PNG file. (The Java ImageIO library uses the default compression ratio of
0.75f
for the compression quality of the JPEG.)Results:
Taking a look at the image itself, the JPEG has a little bit of artifacting, but it wasn't very noticeable until I zoomed in with an image editor. Of course, the PNG image is lossless, so it was an exact representation of the original.
To conclude, whether an image is smaller with PNG or JPEG is really up to the source -- there are cases where JPEG can be larger than a PNG and yet the PNG can be better quality. Of course, in practice, generally PNG will be larger than JPEG for a given image.
您可能希望减少在图像中编码的颜色数量。 尝试仅使用 256 色保存漫画,您会发现尺寸减小了很多。 根据您的具体绘画风格,我就足够了。
You may want to cut down on how many colours you are encoding in your image. Try saving your comic with only 256 colours and watch the size decrease a lot. Depending on your specific drawing style, that me be enough.
我绘制了许多大型手绘电路图,并将其扫描为灰度,以便在计算机化文档中使用; 无论是在可视质量还是文件大小方面,LZW 压缩的 TIFF 总是胜过 JPEG,我认为这是因为 TIFF 可以利用 RLE 编码的空白。 我不确定 PNG 是否也可以做到这一点,或者 RLE 是否可以扩展到多色图像和图像。 不仅仅是黑/白。
编辑:我刚刚尝试了我的一幅灰度手绘图; TIFF 可以以大约 2:1 的速度击败 PNG(43K 与 83K 使用 ImageMagick 转换为从原始 TIFF -> PNG -> TIFF 再次仔细检查 ImageMagick 是否正在生成两种文件格式,并确保我的原始程序没有生成 TIFF 时效果不佳),但这只是因为 TIFF 使用 8 位/像素(灰度)而 PNG 使用 24 位/像素(RGB)。
编辑2:没关系,我只是能够使用
pngcrush -c 0
来确保图像是灰度的。 PNGcrush 将 RGB 版本降至 67K,灰度降至 34K。 好的!编辑3:只是程序的一点:在我看来,选择这种类型的许多不同图像作为标准基准,并在基准集中尝试不同的技术会更有意义,而不仅仅是一堆堆积如山的武断言论。 这似乎是一个需要经过充分测试的经验解决方案的问题。
I've drawn a number of large hand-illustrated circuit diagrams which I scan in as grayscale for use in computerized documents; LZW-compressed TIFF always wins hand over JPEG, both in viewable quality and file size, I think because TIFF can take advantages of RLE encoding for whitespace. I'm not sure whether PNG can do this too, or whether RLE can be extended for multicolor images & not just black/white.
edit: I just tried one of my grayscale hand drawings; TIFF can beat PNG by about 2:1 (43K vs. 83K using ImageMagick convert to go from original TIFF -> PNG -> TIFF again to double-check that ImageMagick is producing both file formats and ensure that my original program didn't do a bad job producing the TIFF) but only because TIFF uses 8bits/pixel (grayscale) and PNG uses 24bits/pixel (RGB).
edit 2: never mind, I just was able to use
pngcrush -c 0
to ensure the image is grayscale. PNGcrush got the RGB version down to 67K and the grayscale down to 34K. Nice!edit 3: Just a point of procedure: It seems to me that it would make a heck of a lot more sense to pick a number of different images of this type to choose as standard benchmarks, and just try different techniques across the benchmark set, rather than just a bunch of stack-overfloids pontificating. This seems like a problem that needs a well-tested empirical solution.
无论无损压缩有多么出色,有损压缩总是更好,因为它的限制更少。
想象一下,有一天他们为漫画发明了一种比 jpeg 更好的无损压缩,显然第二天有人会修改它以压缩更多,甚至可能,如果这意味着某些信息丢失。
No matter how great a lossless compression is, a loss compression will always be better, because it just has fewer limitations.
Imagine that one day they invent some lossless compression better than jpeg for comics, obviously the next day someone will modify it to compress more, even, and probably, if it means that some info is lost.
在抗锯齿和渐变之间,图像中的颜色可能比您想象的要多。
Between anti-aliasing and gradients, there are probably more colors in the image than you think.
绘制与未绘制、网络漫画与任何其他类型的图像……这些都不相关。 网络漫画的绘制方式或颜色布局或其他您认为不同的细节。 但你可以打赌,数十年的图形研究和开发已经充分考虑到了这一点,并且以图形优化为生的人们已经突破了极限。
如果有比 JPEG、GIF、PNG 等更好的压缩算法,那么您不认为它会得到广泛使用吗? 如果您正在寻找最近的突破,那么我认为您可能是在浪费时间,因为 1)您必须花费大量精力来使您的前端压缩与人们使用的任何查看器(例如浏览器)兼容) 和 2) 如果它从当前格式中获得显着收益,那么它将很快得到广泛传播。
如果我被否决了,那我一定没有很好地解释自己。
认为网络漫画因为是手绘的或有大量颜色重复而属于某些特殊领域是有点愚蠢的。 查找相同颜色的大块是图像压缩的绝对基础之一。
为自己准备一个好的图形程序,并使用您的特定图像,看看哪种导出格式可以产生最小的图像尺寸,同时保留您想要的质量。 对于不同的图像来说,它会有所不同。
Drawn vs. not drawn, web comics vs. any other type of image... that's not relevant. The specifics of how web comics are drawn or the colors are laid out or whatever is something you're perceiving as different. But you can bet that decades of graphics research and development have that fully taken into account, and the people that do graphics optimizations for a living have pushed the envelope.
If there was a better compression algorithm than JPEG, GIF, PNG, etc. then don't you think it would be in wide-spread use? If you're looking for fairly recent breakthroughs then I think you're probably wasting your time, as 1) you'd have to expend quite a bit of effort to make your front-end compression compatible with whatever viewer people use (like browsers) and 2) if it had significant gains from current formats then it would become wide-spread fairly quickly.
If I'm getting down-voted I must not have explained myself very well.
Thinking that web comics are in some special domain because they're hand-drawn or have lots of color repetition is a bit silly. Finding large blocks of the same color is one of the absolute basics of image compression.
Get yourself a good graphics program, and using your specific image, see which of its export formats yields the smallest image size while retaining the quality you desire. It is going to be different for different images.
对于笔墨图像,GIF 中的压缩方案可以创造奇迹。
JPEG 压缩不适合这种图像。
For pen-and-inkish images, the compression scheme in GIF can work wonders.
JPEG compression is ill-suited to that kind of image.
作为一个做过大量漫画着色工作以及照片处理工作的人,我可以有把握地说,与普通照片相比,普通网络漫画中经常会发生很多事情。
假设图像是在 Photoshop 或 Painter(通常通过平板电脑)中完成的,那么在普通网络漫画中通常会使用许多滤镜或图层。 阴影、反射、不透明度、背景图像等等都纳入考虑范围,其中许多直接来自滤镜或图层叠加,通常有许多颜色。
很多时候你必须考虑你的观众。 如果每天有 20 名访客,那么优化图像真的值得吗? 我可能会认为这完全取决于您的网络漫画的大小和内容。 如果你能摆脱 PNG 那么我会坚持使用它。 在网络漫画中,通常没有什么值得使用 JPG 的内容。
As someone who has done a lot of colouring work for cartoons, as well as photo-manipulation work I can safely say that there is often a lot going on inside the average web-comic when compared to a normal photo.
Assuming that the image is done in Photoshop or Painter (usually from a Tablet) there are often a number of filters or layers at work in the average web-comic. Shading, reflection, opacity, background images and far more come into the equation and with many of these being straight from filters or layer overlays there are often many colours in place.
A lot of the time you have to think of your audience. It is really worth optimising your images if you get 20 visitors a day? I'd probably argue that it is completely down to the size and content of your web-comic. If you can get away with PNG then I'd stick with it. More often than not in web-comics there is little going on to warrant using JPG.
我使用 OPTIPNG 获得最佳过滤器(具有合理的级别),然后运行 ADVDEF -4 -z
http://advancemame.sourceforge.net/comp-readme.html(不是 Advpng因为 Advpng 删除了过滤器)以优化放气。
您也可以尝试 pngout http://www.advsys.net/ken/utils.htm
有一个 Irfanview 插件。
它使用与 Kzip 相同的 deflate 实现,通常比 7-zip 更好,但速度慢得多。
编辑:
okcancel20031003.gif 您最喜欢的“程序员”卡通片是什么? 256颜色 147KB
PNG(油漆)126KB
PNG (Irfanview) 120 KB
PNG (Irfanview) +
Optipng -o5 120KB(小 525 字节)9s
优化 + ADVDEF 114 KB 9s+0.9s
PngOut 114 KB 6s
BMP 273 KB
BMP +
7z(LZMA -fb 273)107 KB
RAR(最佳)116 KB
BMF -S 90 KB 0.3 秒
Paq8o10t -4 79 KB 35s
I use OPTIPNG to get the best filter (with a sane level) and then I run ADVDEF -4 -z
http://advancemame.sourceforge.net/comp-readme.html (Not Advpng because Advpng removes the filters) to optimize the deflate.
Also you can try pngout http://www.advsys.net/ken/utils.htm
Has a plugin for Irfanview.
It uses the same deflate implementation of Kzip, which is usually even better than 7-zip but much slower.
EDIT:
okcancel20031003.gif What's your favorite "programmer" cartoon? 256 colors 147KB
PNG (Paint) 126KB
PNG (Irfanview) 120 KB
PNG (Irfanview) +
Optipng -o5 120KB (525 bytes smaller) 9s
Optipng + ADVDEF 114 KB 9s+0.9s
PngOut 114 KB 6s
BMP 273 KB
BMP +
7z (LZMA -fb 273) 107 KB
RAR (Best) 116 KB
BMF -S 90 KB 0.3s
Paq8o10t -4 79 KB 35s
我认为这里缺少的信息是图像压缩与格式相关。 当然,有人可能会想出一种非常适合网络漫画家创建的图像类型的压缩算法。 然而,一旦您采用新的 uber-comic-image 格式并发出 PNG、JPG 或 GIF,颜色信息将受到 PNG、JPG 或 GIF 压缩机制的规则的约束,您将失去您的所有好处。新的图像格式。
这是另一种思考方式。
这个神话般的超级漫画也会发生同样的情况-图像格式。
另一种选择是让主要浏览器供应商支持超级漫画图像的诞生。 我会将不作为练习的原因留给观众。
I think the missing piece of information here is Image Compression is Tied to the Format. It's certainly possible that someone could come up with a compression algorithm that was/is well suited for the kind of images that web cartoonists create. However, once you took the new uber-comic-image format and emitted a PNG, JPG or GIF, the color information would be subject to the rules of the PNG, JPG or GIF compression mechanism and you'd lose all the benefit of your new image format.
Here's another way to think about it.
The same thing would happen to this mythical uber-comic-image format.
The alternative would be getting the major browser vendors to support uber-comic-image nativity. I'll leave the reasons behind that not working as an exercise to the viewer.