tinytag icon indicating copy to clipboard operation
tinytag copied to clipboard

[Question] - detect image encoding / format

Open mdougher opened this issue 3 years ago • 0 comments

a sort of followup to #100 / #113 I have a situation where i need to detect the image character set as the formatting found in #100 / #113 cause image loading to fail. Basically, the head unit in my car also fails to parse these files (apparently), and produces no album art.

Right now, i can get by using an older version of tinytag that does not have the fix from #100 / #113 . I try to load the image and it fails due to the parsing error, and i flag it as something i need to fix manually.

With the newer version of tinytag that has this fix, how can I detect that this is an image that needs to be converted? is there something like this? image_data = tags.get_image() if image_data.format != 'LATIN': raise Exception("Invalid image type") of course it probably wouldn't just be a check for 'LATIN' or whatever. But i'm just hoping there is a way to check for the presence for this format or not.

Similarly, my car head unit appears to not like PNG format images. It looks like there is "PNG" in the image data in the first 10 bytes or so. I can have a check like this: image_data = tags.get_image() if b'PNG' in image_data[:20]: raise Exception("PNG Image Format detected!") but this feels really clumsy, and may not actually work in all cases... is there something better i can do?

thanks in advance!

mdougher avatar Jun 08 '22 15:06 mdougher