I'm working on a python web service. It calls another web service to change the picture of a profile.
It connects to another web service. This web service can only accept pictures that are 4 MB or smaller.
I will put the checking in the first web service. It uses PIL to check if the base64 string is a valid image. However, how do I check if the base64 string will create a 4 MB or smaller image?
Very roughly, the final size of Base64-encoded binary data is equal to 1.37 times the original data size + 814 bytes (for headers). You can use ContentLength property of the request to determine what the size is in bytes, although if you are uploading more then one image, it might be trickier.
more than 2500x2500 pixels. 4-8kb in size.
Length of data Base64 uses 4 ascii characters to encode 24-bits (3 bytes) of data.
File size. Image Base64 encoding is not the most efficient way to encode data when it comes to filing size. This is because the process always results in a 20%-25% increase in file size at least. For example, if you have a binary file that is 1000 bytes in size, after Base64 encoding, it will be 1250 bytes in size.
Multiply the length of the data by 3/4, since encoding turns 6 bytes into 8. If the result is within a few bytes of 4MB then you'll need to count the number of =
at the end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With