Search code examples
javascriptstringimagebase64

What is the ratio between an image size and the length of its base64 string conversion?


I have a 200Kb jpg and I want to convert it into a base64 string.

How long will that base64 string be approximately ?

The reason I'm asking is because I'd like to store that image as a base64 string in a "container" that only allows strings of a maximum length is 65000 characters.

I tried to find out for myself using the Chrome's console but the browser keeps freezing up due to the length of the base64 generated string, as soon as I assign it to a variable and the do :

x = 'base64.....'; // ridiculously long string
x.length;

Solution

  • As already stated in comments, there's no way of giving an exact number as it's depending on how the data is packed. It will however be larger than the source file. A ballpark figure is around 270 000 characters.

    An easy way to check this is to upload a few images to an online converting service such as https://www.base64-image.de/