Is there a grayscale JPG format?

前端 未结 2 856
[愿得一人]
[愿得一人] 2021-01-05 07:48

When converting a color JPG image to grayscale, and saving it back to JPG, one can usually see at least 20% file size reduction, which seems natural.

Question:

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-05 08:21

    Is there a specific "grayscale" format in the JPG specifications?

    Yes, and it is well supported. It isn't used commonly these days, but most everything can read it.

    Or is a "grayscale JPG" just usually a color RGB JPG where R value==G value==B value, and thus the file size reduction results from a compression of 3-times-duplicated numbers?

    Not all APIs are going to expose all of the features available. The greyscale handling is specific to the format and isn't available in all other formats. The Canvas API, in particular, tries to standardize over all possible export formats. Therefore, only a subset of features are supported.

    When you save an image via the Canvas API, it's likely that you're saving a JPEG with chroma components, and they are effectively null and are compressing well. (That being said, the specific behavior is undefined, and a browser could choose to optimize and save a greyscale JPEG by detecting greyscale is all that's required.)

提交回复
热议问题