fix(media): Handle HEIC files with wrong extension - v1.4.2
iOS sometimes saves HEIC with .jpeg extension. Pillow fails to open these as JPEG, so now we fallback to trying pillow-heif directly when initial open fails. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -108,7 +108,23 @@ def validate_image(file_data: bytes, filename: str) -> Tuple[bytes, str, int, in
|
|||||||
# Re-open after verify (verify() closes the file)
|
# Re-open after verify (verify() closes the file)
|
||||||
img = Image.open(io.BytesIO(file_data))
|
img = Image.open(io.BytesIO(file_data))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError(f"Invalid or corrupted image: {e}")
|
# v1.4.2: If Pillow can't open, try explicitly as HEIC
|
||||||
|
# iOS sometimes saves HEIC with .jpeg extension
|
||||||
|
if HEIC_SUPPORTED:
|
||||||
|
try:
|
||||||
|
heif_file = pillow_heif.read_heif(file_data)
|
||||||
|
img = Image.frombytes(
|
||||||
|
heif_file.mode,
|
||||||
|
heif_file.size,
|
||||||
|
heif_file.data,
|
||||||
|
"raw",
|
||||||
|
)
|
||||||
|
# Mark as HEIF so conversion happens below
|
||||||
|
img.format = 'HEIF'
|
||||||
|
except Exception:
|
||||||
|
raise ValueError(f"Invalid or corrupted image: {e}")
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Invalid or corrupted image: {e}")
|
||||||
|
|
||||||
# HEIC/HEIF conversion (v1.4.2)
|
# HEIC/HEIF conversion (v1.4.2)
|
||||||
# HEIC cannot be displayed in browsers, convert to JPEG
|
# HEIC cannot be displayed in browsers, convert to JPEG
|
||||||
|
|||||||
Reference in New Issue
Block a user