Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/launchpad/size/insights/apple/image_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import pillow_heif # type: ignore

from PIL import Image, ImageFile
from PIL import Image, ImageFile, UnidentifiedImageError

from launchpad.size.insights.insight import Insight, InsightsInput
from launchpad.size.models.apple import AppleAppInfo
Expand Down Expand Up @@ -121,6 +121,10 @@ def _analyze_image_optimization(
logger.info("Skipping %s because it has no full path", file_info.path)
return None

if file_info.size == 0:
logger.info("Skipping %s because it is empty (0 bytes)", file_info.path)
return None

try:
with Image.open(file_info.full_path) as img:
img.load() # type: ignore
Expand Down Expand Up @@ -159,6 +163,9 @@ def _analyze_image_optimization(
idiom=file_info.idiom,
colorspace=file_info.colorspace,
)
except UnidentifiedImageError:
logger.warning("Skipping %s: cannot identify image format", file_info.path)
return None
except Exception:
logger.exception("Failed to open or process image file")
return None
Expand Down
Loading