alextanhongpin / compress.js

A simple JavaScript based client-side image compression algorithm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

File size from base64 calculation

davejm opened this issue · comments

Out of interest, how did you come up with this calculation? @alextanhongpin

return (len - 814) / 1.37

Well, initially I thought that the size in base64 is supposed to be 4/3 times the original length, but then I came across this: https://en.wikipedia.org/wiki/Base64

Very roughly, the final size of Base64-encoded binary data is equal to 1.37 times the original data size + 814 bytes (for headers). The size of the decoded data can be approximated with this formula:

bytes = (string_length(encoded_string) - 814) / 1.37

Interesting. Thanks!