Compute a simplified aspect ratio from width and height, and optionally scale one edge to a target size while preserving that ratio.
How it works
Width and height are rounded to integers and reduced by their greatest common divisor to a string like 16:9 or 4:3 (via the shared image helper). If you supply a positive target width, height is scaled proportionally; if you supply a positive target height, width is scaled. Supplying both targets at once is rejected so the intent stays unambiguous. Leaving both targets at zero returns only the reduced ratio.
When to use it
- Plan video or image crop boxes before editing
- Match a design frame to a known ratio
- Derive the missing dimension when resizing for a fixed width or height
Limitations
Non-pixel units work mathematically but are not labeled. Sub-pixel sources are rounded. This does not crop or encode media files—it only computes numbers.
Example
1920×1080 yields ratio 16:9. With target width 1280, scaled size is 1280×720. Providing both target width and height returns invalid-target.