admin管理员组文章数量:1334887
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;
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;
Share
Improve this question
asked Apr 1, 2016 at 9:04
user2272048user2272048
3
- 200kb is 200000 "characters", more than 3 times longer than 65000. Common sense should tell that the base64 representation can't possibly be 3 times smaller than the original file. Othewise it would be by far the world's best pression algorithm and we'd use it for everything. – JJJ Commented Apr 1, 2016 at 9:09
- 2 base64-encoding is approximately 4/3 the original size, due to how the bits are packed. So a 200Kb jpg will be about 266Kb in its base64-encoded form. – Niet the Dark Absol Commented Apr 1, 2016 at 9:11
- 1 Read this stackoverflow./questions/4715415/… and this stackoverflow./questions/11402329/base64-encoded-image-size – Lewis Commented Apr 1, 2016 at 9:20
2 Answers
Reset to default 4The approximate size of the string is 135% of the original size due to the expansion that takes place (according to my NetBSD manpage of uuencode). To encode n bytes you need 4*ceil(n/3) bytes and additional line breaks.
As already stated in ments, 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/
本文标签:
版权声明:本文标题:javascript - What is the ratio between an image size and the length of its base64 string conversion? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742370910a2462216.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论