A small metadata contract for reviewing photo crops
A photo handoff often includes a final image, an intended destination and a sentence such as “make it square.” That is not quite enough information for another person to review the export. A square file may be too small for the destination; a large file may have the wrong aspect ratio. Both checks are useful, but they answer different questions. This article builds a tiny, local metadata check…
A metadata check for photo crop handoffs is presented in this article. It does not manipulate images or decide on edits; instead, it verifies dimensions provided by a caller. The function `review_crop` takes width, height, target width, and target height as inputs and returns a dictionary with three keys: `ratio_matches`, `needs_upscale`, and `source_ratio`.
The function raises a `ValueError` if the dimensions are not finite positive numbers. It checks if the aspect ratios of the source and target match and whether either dimension of the source is smaller than its corresponding target dimension. The tolerance for comparing ratios is an absolute value, not a universal image-quality threshold.
The code is a standalone example and should not be integrated with any photo service. The article also includes tests for the function using Python's standard library.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.