E.g., if an image is, say, 600px x 400px and the PNG format produces a smaller file size than JPG, does this hold true at any image size? If the image were 600,000px x 400,000px would the two file sizes still have the same relative proportions? Or is it possible that JPG's compression means that PNG will eventually produce a larger file size past some number of megapixels?


1 Answer 1

  1. JPEG images can't be that big; their maximum size is (2¹⁶-1)×(2¹⁶-1). (doesn't really matter)
  2. These are fundamentally different file formats, and their compression stems from different properties: Where JPEG is a lossy format who is able to drastically reduce the file size of content that has photographic properties (mostly: low-pass behaviour in 8×8 pixel blocks) at different levels of lossiness, PNG is lossless and compresses especially well on images with similar rows.
    Thus, the size of the images depend on the content. You can't directly extrapolate from a small image to a larger version: it depends on the content of the original large image whether it compresses better in JPEG (for a given lossiness factor) or PNG.

Hence, no statement of the sort you seem to be looking for can be made, in general.

Specfically, for images that are large and that results in large swaths of identical pixels, JPEG always operates on blocks of 8×8 pixels. Even if there's a lot of monocoloured blocks, these still have to be stored and later entropy-coded in JPEG; this leads to repeating bit patterns, but not necessarily constant 0-bytes, having to go through a Huffmann-alike compressor.

In PNG, identical runs of pixels will be converted to differences to neighboring pixels; thus, large portions of 0-runs exist in large pictures with constant areas. The DEFLATE algorithm that follows this differential encoding is very efficient in reducing consecutive constant values to very few bits.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.