Automating Photo Processing: HEIF Conversion and Layout Generation
Recently my wife tasked me with printing hundreds of photos from mixed sources (iPhone, camera, WhatsApp) for her scrapbooking activities, which raised two primary technical challenges:
- Format incompatibility: HEIF (
.heic
) files from iOS Live Photos not being supported with the printing layout software that I ad installed - Manual layout inefficiency: Arranging the photos in a print layout was manual and time-consuming
Rather than relying on third-party online tools or manual processes, I developed two Python utilities to automate the entire workflow:
- HEIC Converter: Batch converts HEIF images to standard formats (JPEG/PNG/WEBP)
- Layout Generator: Arranges images in grid layouts optimized for printing
HEIC to JPEG Conversion⏚
Source: heic_converter
Key Dependencies:
pyheif
: HEIF/AVIF decoder support via libheifpillow (PIL)
: Image processing
Description:
The converter uses pyheif
to decode HEIC files into raw image data, then leverages Pillow to perform the format conversion. The tool supports multiple output formats and includes comprehensive error handling for corrupted files.
PDF Layout Generation⏚
Source: layout_gen
Key Dependencies:
pillow
: Image processingreportLab
: PDF generation and document layout
Description: The layout generator creates PDF documents with configurable grid layouts, automatically rotating and cropping images to optimize for printing.
Current Limitations & Future Enhancements:
-
Cropping Algorithm: Currently uses edge-based cropping without content-aware centering, meaning subjects near image edges may be cropped out.
-
Uniform Sizing Constraint: All images in a layout use identical dimensions, requiring separate invocations if dealing with mixed aspect-ratios.