I am working on image processing in Python and facing an issue with extracting the original file extension from base64 image data. Initially, I open the image and read it as binary using the following code:
with open(img_path_input, 'rb') as img:
img_bin = img.read()
After obtaining the binary data (img_bin
), I convert it to base64 format using the base64
module like this:
img_base64 = base64.b64encode(img_bin).decode()
However, I need to recover the original file extension later on without relying on storing or passing the original extension using the img_path_input
. I am wondering if there is an alternative method within the base64
module or if the extension is implicitly encoded in the base64 string.
Any suggestions or alternatives to solve this problem would be greatly appreciated.