Skip to content

feat: Render the exact size the URL advertises - #148

Merged
elektronaut merged 1 commit into
mainfrom
exact-size-rendering
Sep 20, 2026
Merged

elektronaut merged 1 commit into
mainfrom
exact-size-rendering

Conversation

@elektronaut

Copy link
Copy Markdown
Owner

Follow-up to #147, which flagged this path as still losing a pixel. The helper floors the fitted size into the URL and into the tag's width/height, but the pipeline refit that floored box against the source, so the other axis shrank — a 320x200 image served 246x154 for a tag claiming 247x154, and 226 of the 2055 distinct sizes the helpers generate for that image rendered smaller than advertised.

ImageProcessor#resize is split in two: resize keeps its fit-inside-a-box semantics, and the new resize_exact forces the size it is given, which ProcessedImage#crop_and_resize and Model::Transformations#resize now use since both already computed the exact size. That brings the mismatches to zero, at the cost of stretching off-ratio sizes by a median of 0.73% and at most 6.43% — a stretch the browser already performs today with a worse resampler, since the tag advertises the forced size either way.

The variant lookup key is unchanged, so existing variants keep serving their old one-pixel-short blobs until they are purged.

The helper floors the fitted size into the URL and into the tag's
width and height, but the pipeline refit that floored box against the
source, so the other axis shrank: a 320x200 image served 246x154 for
a tag claiming 247x154. Of the 2055 distinct sizes the helpers
generate for that image, 226 rendered smaller than advertised.

Split ImageProcessor#resize in two. resize keeps its fit-inside-a-box
semantics; the new resize_exact forces the size it is given.
ProcessedImage#crop_and_resize and Model::Transformations#resize both
already computed the exact size, so they now use it. That brings the
226 mismatches to zero.

Forcing stretches sizes that don't land on the image's ratio, by a
median of 0.73% and at most 6.43%. The browser already performs that
stretch today, with a worse resampler, since the tag advertises the
forced size either way.

The variant lookup key is unchanged, so existing variants keep
serving their old one-pixel-short blobs until they are purged.
@elektronaut
elektronaut enabled auto-merge (squash) September 20, 2026 16:11
@elektronaut
elektronaut merged commit 057523f into main Sep 20, 2026
6 checks passed
@elektronaut
elektronaut deleted the exact-size-rendering branch September 20, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant