JPEG:尺寸与压缩
这里有一个非常简单但具体的问题:
我并不完全熟悉压缩图像的 JPEG 标准。当 X 尺寸(宽度)非常大且 Y 尺寸(高度)非常小时(反之亦然)或者当两者几乎相等时,它是否会创建更好的(即,在相似质量下文件尺寸更小)图像?
我对此的实际用途是CSS sprites。如果一个网站由数百个 CSS sprite 组成,那么最好最小化 sprite 文件的大小,以帮助网速较慢的用户并减少服务器负载。如果 JPEG 标准在单条水平线上运行良好,但垂直移动需要更多的复杂性,那么将 100 个 16x16 CSS 精灵的图像设置为 1600x16 是有意义的。
另一方面,如果 JPEG 标准在水平工作时非常复杂,但可以轻松地从行移动到行,则可以通过将图像设为 16x1600 来制作更小的文件或获得更高的质量。
如果最佳压缩发生在图像为完美正方形时,您会希望最终图像为 160x160
Pretty simple but specific question here:
I'm not entirely familiar with the JPEG standard for compressing images. Does it create a better (that being, smaller file size at a similar quality) image when the X dimension (width) is very large and the Y dimension (height) is very small, vice versa, or when the two are nearly equal?
The practical use I have for this is CSS sprites. If a website were to consist of hundreds of CSS sprites, it would be ideal to minimize the size of the sprite file to assist users on slower internet and also to reduce server load. If the JPEG standard operates really well on a single horizontal line, but moving vertically requires a lot more complexity, it would make sense for an image of 100 16x16 CSS sprites to be 1600x16.
On the other hand if the JPEG standard has a lot of complexity working horizontally but moves from row to row easily, you could make a smaller file or have higher quality by making the image 16x1600.
If the best compression occurs when the image is a perfect square, you would want the final image to be 160x160
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MPEG/JPEG 块机制会(非常轻微地)倾向于每个维度上压缩块大小的精确倍数的图像大小。然而,除此之外,格式不会关心块是垂直的还是水平的。
所以,你的问题的直接答案是“正方形和任何东西一样好”,只要你的精灵很容易分成 JPEG 压缩块(只要确保它们是 8、16、24 或 32 像素宽,你就会没事)。
然而,我想更进一步说,对于“大多数”恶意,如果您的初始主图像是 GIF 而不是 JPG,您将获得更小的图像尺寸和更清晰的分辨率,如果您可以使用减少的调色板。考虑一下为什么“数百个精灵”需要 JPG。
The MPEG/JPEG blocking mechanism would (very slightly) favor an image size that is an exact multiple of the compression block size in each dimension. However, beyond that, the format won't care if the blocks are vertical or horizontal.
So, the direct answer to your question would be "square is as good as anything", as long as your sprites divide easily into a JPEG compression block (just make sure they are 8, 16, 24 or 32 pixels wide and you'll be fine).
However, I would go a bit further and say that for "most" spites, you are going to have a smaller image size, and clearer resolution if you have the initial master image be GIF instead of JPG, even more so if you can use a reduced color palette. Consider why would you need JPG at all for "hundreds of sprites".
看起来 JPEG 的压缩率不受图像尺寸的影响。然而,看起来你的尺寸应该是 8 的倍数,但在你所有的例子中,你的尺寸都是 16 的倍数,所以你应该没问题。
http://en.wikipedia.org/wiki/JPEG#JPEG_codec_example
如果我没记错的话当相同的颜色出现在水平拉伸而不是垂直拉伸中时,PNG(无损)效果要好得多。为什么你要把你的精灵做成 JPEG 格式?如果它们的颜色设置有限(如果您有 16x16 精灵,无论动画与否,则可能会出现这种情况),PNG 实际上可能会产生更好的文件大小和完美的图像质量。
It looks like JPEG's compression ratio isn't affected by image dimensions. However, it looks like your dimensions should be multiples of 8 but in all your examples you had multiples of 16 so you should be fine there.
http://en.wikipedia.org/wiki/JPEG#JPEG_codec_example
If I remember correctly, PNG (being lossless) operates much better when the same color appears in a horizontal stretch rather than a vertical stretch. Why are you making your sprites JPEG? If they are of a limited color-set (which is likely if you have 16x16 sprites, animated or not), PNG might actually yield better filesizes with perfect image quality.