Handle more iPhone photo variants
This commit is contained in:
+27
-10
@@ -128,16 +128,21 @@ def public_text(text):
|
||||
|
||||
def web_image(raw, destination):
|
||||
with Image.open(io.BytesIO(raw)) as original:
|
||||
if original.format not in {"JPEG", "PNG", "WEBP", "HEIF"}:
|
||||
raise ValueError("Use JPEG, PNG, WebP, or HEIC photos")
|
||||
if original.format not in {"JPEG", "PNG", "WEBP", "HEIF", "AVIF", "TIFF"}:
|
||||
raise ValueError("Use JPEG, PNG, WebP, HEIC, AVIF, or TIFF photos")
|
||||
taken_at = exif_photo_date(original.getexif())
|
||||
image = ImageOps.exif_transpose(original)
|
||||
image.thumbnail((GALLERY_MAX_EDGE, GALLERY_MAX_EDGE), Image.Resampling.LANCZOS)
|
||||
if image.info.get("icc_profile"):
|
||||
image = ImageCms.profileToProfile(
|
||||
image, ImageCms.ImageCmsProfile(io.BytesIO(image.info["icc_profile"])),
|
||||
ImageCms.createProfile("sRGB"), outputMode="RGB",
|
||||
)
|
||||
try:
|
||||
image = ImageCms.profileToProfile(
|
||||
image, ImageCms.ImageCmsProfile(io.BytesIO(image.info["icc_profile"])),
|
||||
ImageCms.createProfile("sRGB"), outputMode="RGB",
|
||||
)
|
||||
except (ImageCms.PyCMSError, OSError, ValueError, SyntaxError):
|
||||
# Bad embedded color metadata should not block an otherwise
|
||||
# decodable phone photo.
|
||||
image = image.convert("RGB")
|
||||
if image.mode in {"RGBA", "LA"} or "transparency" in image.info:
|
||||
rgba = image.convert("RGBA")
|
||||
background = Image.new("RGB", image.size, "white")
|
||||
@@ -362,10 +367,22 @@ def create_app(data_dir=None, token=None):
|
||||
capture_dates.append(batch_date or
|
||||
(supplied_dates[index] if supplied_dates else embedded_date) or
|
||||
received_at)
|
||||
except (UnidentifiedImageError, OSError, ValueError, SyntaxError,
|
||||
Image.DecompressionBombError, Image.DecompressionBombWarning,
|
||||
ImageCms.PyCMSError):
|
||||
abort(400, f"Photo {index + 1} is unsupported, damaged, or exceeds 60 megapixels")
|
||||
except (Image.DecompressionBombError, Image.DecompressionBombWarning) as error:
|
||||
app.logger.warning("Photo %d exceeded the pixel limit", index + 1,
|
||||
exc_info=error)
|
||||
abort(400, f"Photo {index + 1} exceeds the 60 megapixel limit")
|
||||
except UnidentifiedImageError as error:
|
||||
app.logger.warning("Photo %d could not be identified", index + 1,
|
||||
exc_info=error)
|
||||
abort(400, f"Photo {index + 1} is not a supported still-image file")
|
||||
except ValueError as error:
|
||||
app.logger.warning("Photo %d has an unsupported format", index + 1,
|
||||
exc_info=error)
|
||||
abort(400, f"Photo {index + 1}: {error}")
|
||||
except (OSError, SyntaxError, ImageCms.PyCMSError) as error:
|
||||
app.logger.warning("Photo %d could not be decoded", index + 1,
|
||||
exc_info=error)
|
||||
abort(400, f"Photo {index + 1} could not be decoded ({type(error).__name__})")
|
||||
# Preserve existing IDs when omitted; named highlights participate in deduplication.
|
||||
if highlight:
|
||||
digest.update(b"\0highlight\0" + highlight.encode())
|
||||
|
||||
Reference in New Issue
Block a user