0

The tests I made were not conclusive. There are imagens with 3MB, but with small dimensions that generate small strings. There are images with few Ks, but with large dimensions that generate large strings. What is the weight of each of these characteristics? And does the image format count?

  • What format are the images in? The file size (of any file type - not just image) will increase by 33% after saving in base 64. See [the Wikipedia article](https://en.wikipedia.org/wiki/Base64) for more information. – Wai Ha Lee Jan 14 '19 at 09:42
  • Possible duplicate of [Base64: What is the worst possible increase in space usage?](https://stackoverflow.com/questions/4715415/base64-what-is-the-worst-possible-increase-in-space-usage) – Wai Ha Lee Jan 14 '19 at 09:44

1 Answers1

0

There is a direct relationship between:

  • the size of a JPEG-encoded image and its base64 representation,
  • between a TIFF-encoded image and its base64 representation,
  • between a PNG-encoded image and its base64 representation.

That relationship is that the base64 version will be around 33% bigger.

However, there is no relationship between an image and its base64 representation if the file format is not specified. The reason is that the file format (and image content) are likely to grossly affect the compression achieved - if indeed the format supports compression.

For example, the same simple red rectangle of size 1024x768 pixels could take:

  • 5MB to encode as an uncompressed TIFF, or
  • 5kB as an LZW compressed TIF, or
  • 9kB as a JPEG, or
  • 2.5MB as a BMP

all we can say is that the base64 versions will be around 33% bigger.

Note further, that it is not even sufficient to stipulate that you want to predict the size of the base64 representation when, say, JPEG encoded - because the size will still depend on the quality setting used for the JPEG encoding... likewise the compression method and bit-depth used in a TIFF encoder.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432