Skip to content

Commit 8f41392

Browse files
committed
Tighten libvips encoder options and ping robustness
API-review findings (cf. ruby-vips 2.3 / libvips 8.15 docs): * `strip: true` → `keep: :none`. Soft-deprecated in libvips 8.15 in favour of the bitmask `keep:` form. Same effect today, future-proof later; output bytes are unchanged. * `subsample_mode: :on` added explicitly to both writes. libvips' default `:auto` disables 4:2:0 chroma subsampling for Q >= 90, which would silently inflate output ~20-30% if a user bumps the collection-metadata `quality` past that threshold. For a photo gallery 4:2:0 is the right call across the quality range; pin it. At the current defaults (full Q85, thumb Q80) the auto mode would have produced the same output, so today the change is a no-op on the byte stream. * `fail_on: :error` added to the `Vips::Image.new_from_file` ping in `ImageFile#initialize`. For a build tool, a truncated or corrupt source JPEG should abort the build with a clear error rather than silently rendering a half-grey output. Default is `:none` (warnings ignored), which is the wrong default for our use case. Three mozjpeg-style options (`trellis_quant`, `overshoot_deringing`, `optimize_scans`) were considered and skipped: libvips on Ubuntu 24.04 is built against stock libjpeg-turbo, not mozjpeg, so passing them emits warnings and has no effect. Worth revisiting if the CI matrix ever picks up a mozjpeg-libvips build. cache_spec spy counts and the `geometry_string` cache fingerprint are unaffected. The bench delta on the small workload is within noise of the pre-tweak libvips numbers. https://claude.ai/code/session_01AZQRrnPUpfUMCXLu3oTSDN
1 parent 549423d commit 8f41392

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@
99
* **Behaviour change:** EXIF Orientation is now honoured. Sources that
1010
previously rendered sideways (Orientation 5–8) will now render
1111
upright. Output JPEGs no longer carry the orientation tag.
12-
* **Behaviour change:** thumbnails (`*_thumb.jpg`, `*_index.jpg`) are
13-
now progressive JPEGs encoded at Q80 with optimised Huffman tables
14-
and EXIF metadata stripped. Previously they used RMagick's default
15-
encoder settings (baseline JPEG, ~Q75, EXIF retained).
12+
* **Behaviour change:** every rendered JPEG (full-size + thumbs) now
13+
ships as a progressive JPEG with optimised Huffman tables, explicit
14+
4:2:0 chroma subsampling, and all metadata stripped (`keep: :none`).
15+
Thumbnails are encoded at Q80 and full-size renders honour the
16+
collection-metadata `quality` value (default 85). Previously
17+
thumbnails used RMagick's default encoder (baseline JPEG, ~Q75, EXIF
18+
retained). The explicit `subsample_mode: :on` guards against a
19+
silent ~25% file-size jump if a user bumps `quality` to ≥ 90 (where
20+
libvips' `:auto` mode would otherwise switch to 4:4:4).
21+
* **Robustness:** image header reads now use `fail_on: :error`, so a
22+
truncated or corrupt source JPEG aborts the build with a clear
23+
error rather than silently rendering a half-grey output.
1624
* **Behaviour narrowing:** `max_size` values with ImageMagick trailing
1725
flags other than `>` (i.e. `!`, `^`, `@`, `#`) are silently treated
1826
as the plain `WxH` form. cheesy-gallery's own config never used

lib/cheesy-gallery/image_file.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def initialize(site, collection, file, max_size:, quality:)
2020
Jekyll.logger.debug 'Identifying:', path
2121
# autorot so width/height reflect post-orientation pixels — matches
2222
# what Vips::Image.thumbnail will produce at render time.
23-
source = Vips::Image.new_from_file(path, access: :sequential).autorot
23+
source = Vips::Image.new_from_file(path, access: :sequential, fail_on: :error).autorot
2424
fit_inside(source.width, source.height)
2525
end
2626

@@ -42,8 +42,9 @@ def process_and_write(source_path, dest_path)
4242
dest_path,
4343
Q: @quality,
4444
interlace: true,
45-
strip: true,
45+
keep: :none,
4646
optimize_coding: true,
47+
subsample_mode: :on,
4748
)
4849
end
4950

lib/cheesy-gallery/image_thumb.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ def process_and_write(source_path, dest_path)
2626
dest_path,
2727
Q: 80,
2828
interlace: true,
29-
strip: true,
29+
keep: :none,
3030
optimize_coding: true,
31+
subsample_mode: :on,
3132
)
3233
end
3334
end

0 commit comments

Comments
 (0)