Skip to content

fix: round resized heights - #93

Merged
lukeed merged 1 commit into
mainfrom
fix/image-height
Nov 3, 2026
Merged

lukeed merged 1 commit into
mainfrom
fix/image-height

Conversation

@lukeed

@lukeed lukeed commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Summary

Bun.Image truncates the height that it calculates for a width. A 1254×837 source at 960 came out 960×640, not 960×641, so its aspect ratio was a little off from the source and from the width and height that bongo writes. With height: auto, the image then renders a fraction of a pixel shorter than an image from another tool.

  • bongo passes the height, rounded to the nearest pixel, with each width.
  • The height is part of the cache key, so each resized image encodes once more after this change.
  • Docs: the Images page says that each height rounds to the nearest pixel.

Performance

A cold-cache build of a site with 195 resized WebP images, main against this branch, with hyperfine, in both orders: 1.04 ± 0.06 and 0.98 ± 0.07. No change.

bun run bench site: 2.38 s, against 2.34 s on main, in the range of main across runs. No change.

Test plan

  • An 800×600 source at 501 gives 501×376 (main gives 501×375)
  • bun run build, bun test, bunx tsc -p ., bunx tsc -p build

Bun.Image truncates the height it calculates for a width, so a
1254x837 source at 960 came out 960x640 instead of 960x641, a
slightly different aspect ratio than the source. bongo now passes
the rounded height. The height is part of the cache key, so each
resized image is encoded once more.
@lukeed
lukeed merged commit 5096885 into main Nov 3, 2026
4 checks passed
@lukeed
lukeed deleted the fix/image-height branch November 3, 2026 02:37
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