--- /tmp/utils.py 2026-01-06 19:56:00.680007371 +0100 +++ env/lib/python3.13/site-packages/datasette_media/utils.py 2026-01-06 20:12:07.268007831 +0100 @@ -15,14 +15,20 @@ def image_type_for_bytes(b): - image_type = imghdr.what(None, b) - if image_type is not None: - return image_type - # Maybe it's an HEIC? + # Try to detect the image format using Pillow + try: + image = Image.open(io.BytesIO(b)) + return image.format.lower() # Returns format like 'jpeg', 'png', etc. + except Exception as e: + # If Pillow can't identify the image, continue to the HEIC check + pass + + # Maybe it's an HEIC? Check the magic bytes for HEIC detection if len(b) < 12: return None if b[4:12] in heic_magics: return "heic" + return None