Skip to content

fix: Round resized dimensions to whole pixels - #147

Merged
elektronaut merged 1 commit into
mainfrom
resize-float-rounding-bug
Sep 20, 2026
Merged

elektronaut merged 1 commit into
mainfrom
resize-float-rounding-bug

Conversation

@elektronaut

Copy link
Copy Markdown
Owner

ImageProcessor#resize truncated the size it was handed and left vips to fit the image inside the truncated box, so a size that didn't land on a whole pixel lost a pixel on the other axis: Model#resize("100x100") on a 320x200 image rewrote the stored file at 99x62 rather than 100x63, and ProcessedImage recorded 100x63 on the variant while storing a 99x62 blob. It now fits in Ruby at full precision, rounds once, and has vips hit that size exactly rather than fitting a second time against the truncated box.

The render path is unaffected: the controller resizes to the integer size parsed from the URL, and old and new code render those identically across all 2725 sizes the helpers generate for a 320x200 image. That path does lose a pixel, for a separate reason — the helper floors the fitted size into the URL and the pipeline refits it against the source instead of honoring it — which is left for a follow-up.

ImageProcessor#resize truncated the size it was handed and left vips to
fit the image inside the truncated box. A size that didn't land on a
whole pixel lost a pixel on the other axis: Model#resize("100x100") on
a 320x200 image rewrote the stored file at 99x62 rather than 100x63,
and ProcessedImage recorded 100x63 on the variant while storing a 99x62
blob.

Fit in Ruby at full precision, round once, and have vips hit that size
exactly instead of fitting a second time against the truncated box.

The render path is unaffected. The controller resizes to the integer
size parsed from the URL, and old and new code render those
identically.
@elektronaut
elektronaut merged commit 563bd52 into main Sep 20, 2026
6 checks passed
@elektronaut
elektronaut deleted the resize-float-rounding-bug branch September 20, 2026 16:00
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