A
A
Alexey2021-01-24 15:12:28
Python
Alexey, 2021-01-24 15:12:28

How to get image type from base64?

I have this code

tag = TinyTag.get(media_finish23, image=True)
        mp2 = tag.get_image()
        my_string=base64.b64encode(mp2);
        image_3=QImage();
        image_3.loadFromData(QByteArray.fromBase64(my_string), "JPG")

(Where JPG is a picture file type in music)
How can I get the file type of a picture from base64 data?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pcdesign, 2021-01-24
@graymstar

Something like this

from base64 import b64decode
import imghdr

encoded_string = 'image base64 encoded'

decoded_string = b64decode(encoded_string)
extension = imghdr.what(None, h=decoded_string)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question