mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-11 16:24:11 +01:00
3.0 KiB
3.0 KiB
PhotoPrism — Thumbnails Package
Last Updated: November 23, 2025
Overview
internal/thumb builds thumbnails with libvips, handling resize/crop options, color management, metadata stripping, and format export (JPEG/PNG). It is used by PhotoPrism’s workers and CLI to generate cached thumbs consistently.
Context & Constraints
- Uses libvips via govips; initialization is centralized in
VipsInit. - Works on files or in-memory buffers; writes outputs with
fs.ModeFile. - ICC handling: if a JPEG lacks an embedded profile but sets EXIF
InteroperabilityIndex(R03/Adobe RGB,R98/sRGB,THM/thumbnail), we embed an Adobe-compatible profile; otherwise we leave color untouched. - Metadata is removed from outputs to keep thumbs small.
Goals
- Produce consistent thumbnails for all configured sizes and resample modes.
- Preserve color fidelity when cameras signal color space through EXIF interop tags.
- Keep error paths non-fatal: invalid sizes, missing files, or absent profiles should return errors (not panics).
Non-Goals
- Serving or caching thumbnails (handled elsewhere).
- Full ICC workflow management; only minimal embedding for interop-index cases.
Package Layout (Code Map)
vips.go— mainVipsentry: load, resize/crop, strip metadata, export.vips_icc.go— EXIF InteroperabilityIndex handling and ICC embedding.icc.go— lists bundled ICC filenames (IccProfiles) andGetIccProfilehelper.resample.go,sizes.go— resample options and predefined sizes.thumb.goand helpers — naming, caching, file info.- Tests live alongside sources (
*_test.go, fixtures undertestdata/).
ICC & Interop Handling
- EXIF
InteroperabilityIndexcodes we honor (per EXIF TagNames and regex.info):R03→ Adobe RGB (1998) compatible (a98.icc, etc.)R98→ sRGB (assumed default; no embed)THM→ Thumbnail (treated as sRGB; no embed)
- If an ICC profile already exists, we skip embedding.
- Test Files:
testdata/interop_index.jpg— R03 interop tag, no ICC (expects Adobe profile embed).testdata/interop_index_srgb_icc.jpg— R03 tag with embedded ICC (must remain unchanged).testdata/interop_index_r98.jpg— R98 interop tag, no ICC (should stay sRGB without embedding).testdata/interop_index_thm.jpg— THM interop tag, no ICC (thumbnail; should remain unchanged).
- References:
Tests
- Fast scoped:
go test ./internal/thumb -run 'Icc|Vips' -count=1 - Full:
go test ./internal/thumb -count=1
Lint & Formatting
- Format:
make fmt-go - Lint:
make lint-goorgolangci-lint run ./internal/thumb/...
Notes
- When adding ICC files, place them in
assets/profiles/icc/and append toIccProfiles. - Comments for exported identifiers must start with the identifier name (Go style).