Cropping 101 photos into two screens without losing the subject
Cropping 101 photos into two screens without losing the subject The iPhone Duo has two displays that don't share an aspect ratio. The inner screen is landscape, 2670x1878. The cover screen is portrait, 1398x2034. A wallpaper that looks right on one is usually wrong on the other, so every image on Best iPhone Duo ships as two separate crops plus a 4K version. Doing that with Image.thumbnail()…
Cropping photos to fit two different screens without losing the subject's details can be challenging. The iPhone Duo has two screens with different aspect ratios, which means the same image needs to be cropped differently for each screen. Best iPhone Duo ships wallpapers as two separate crops plus a 4K version. To achieve this, the build performs the crop decision itself.
The process starts by determining three target sizes for each source image: 2670x1878 for the inner screen, 3840x2700 for a 4K download, and 1398x2034 for the cover screen. The goal is to keep the part of the image with the most detail while avoiding an accidental frame. One way to determine this is by using edge density as a proxy for the interesting part of the image.
This involves downsampling the image to 320px wide, converting it to greyscale, running an edge filter, and then summing edge pixels into a 1D profile along the axis being cropped.
The pick_offset function then analyzes the edge profile to find the best offset for the crop. It takes into account the size of the crop, the total length of the profile, and a preference value. The prefer term determines the target center of the crop. For the inner screen, it's set to 0.5, dead center, while for the cover screen, it's set to 0.42, slightly shifted towards the top.
After running these calculations, the resulting cropped images are saved as five files for each photo: open.jpg (2670x1878) for the inner screen download, cover.jpg (1398x2034) for the cover screen download, 4k.jpg (3840x2700) for the 4K download, open-thumb.jpg (960x675) for a grid preview, and cover-thumb.jpg (420x611) for a cover preview.
The images are saved as JPEGs with different quality settings for each size. All files are served immutable for a year, and the grid only loads the thumbnails. The accent color for each card is derived from a resized version of the original image.
This cropping method does not account for facial recognition, so if the subject is small and off-center in the image, the edge energy may prioritize a detailed background over the person. Additionally, the offsets aren't stored per image, so if a crop comes out wrong, the only fix is to replace the source photo rather than adjusting a field in the build.
The photos used are Creative Commons from Wikimedia Commons, mostly CC BY 4.0, and each wallpaper page credits the photographer. The full gallery can be viewed at bestiphoneduo.com.
Rewritten by urgent.news; may contain errors — check the original.