When you open outfile in base64_decode_image, you do not specify the ofstream::binary flag like you do in base64_encode_image when reading the image. Without that flag, you're writing in text mode which can alter the data you're writing (when adjusting for newlines).
Decoding and saving image files from base64 C++ - Stack Overflow
url - Decoding Base64 Images - Stack Overflow
decoding base64 image data
Base64 Image Decoder
What Is A Base64 Image Decoder?
What File Types Can Be Decoded From Base64?
Is Base64 Decoding Safe To Use Online?
When you open outfile in base64_decode_image, you do not specify the ofstream::binary flag like you do in base64_encode_image when reading the image. Without that flag, you're writing in text mode which can alter the data you're writing (when adjusting for newlines).
In the base64_decode method in the is_base64 check, the β=β is not taken into account and the method terminates with an error.
Use this web utility:
http://www.motobit.com/util/base64-decoder-encoder.asp
Set the output format to binary, then copy-paste the base64 data that follows data:image/png;base64,; your browser will download the file. Rename it to PNG and you're good to go.
Another way to save the image is just to copy-paste data:image/png;base64, followed by the characters in your browser's url field..
and you'll see the image..
you could then save it to your computer..
Im having trouble decoding some base64 encoded data. I generated the data using 'toDataURL' on a canvas element. I then pass this to some python code using flask.
Im trying to use the 'base64' module but i keep getting the error -
Invalid base64-encoded string: number of data characters (1517) cannot be 1 more than a multiple of 4
This is the python code causing the error -
img_data = request.form["image"]
img_bytes = base64.b64decode(img_data)
img = Image.open(BytesIO(img_bytes))
img = np.array(img)
cv.imshow(img)
cv.waitKey(0)
cv.destroyAllWindows()The line causing the error is -
img_bytes = base64.b64decode(img_data)
The base64 data -
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAAHRyWFlaAAABZAAAABRnWFlaAAABeAAAABRiWFlaAAABjAAAABRyVFJD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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//2Q==
Do i pass this whole string to the decoder, or just some of it?
I have also tried the urlSafe decoder that is included with the base64 module. But i get the same error. What am i doing wrong ...