Skip to main content

fit_logo_cells

Function fit_logo_cells 

Source
pub fn fit_logo_cells(
    img_w: u32,
    img_h: u32,
    cell_w: usize,
    cell_h: usize,
    max_cols: usize,
    max_rows: usize,
) -> LogoFit
Expand description

Fits an image into a cell box preserving its aspect ratio, returning a LogoFit.

Both the image and the box are converted to pixels (via the terminal’s cell dimensions) so the terminal’s non-square cells are accounted for — a 2:1 image in 1:2 cells is 4 columns per row, not 2. The result is the smallest cell rectangle that contains the scaled image, clamped to 1..=max.

This is the single source of truth for a graphical logo’s footprint: the same values feed the protocol escape (so the terminal does not stretch the image) and plan_layout (so the text column is placed against the logo’s real width). Previously the Kitty path hardcoded c=26,r=10 — which forces the image into that rectangle, ignoring aspect entirely, so the 3.56:1 Fedora logo was squashed into a roughly 1:1 box and rendered ~3× too tall — while the layout separately assumed a fixed 40-column width.