photoprism/internal/thumb
2026-01-21 17:08:57 +01:00
..
avatar Merge tag '251130-b3068414c' into PostgreSQL 2025-12-01 17:16:33 +10:00
crop CI: Apply Go linter recommendations to "internal/thumb/..." #5330 2025-11-23 08:47:17 +01:00
frame CI: Apply Go linter recommendations to "internal/thumb/..." #5330 2025-11-23 08:47:17 +01:00
testdata Thumbs: Enhance embedding of ICC profiles based on InteropIndex #5178 2025-11-23 12:56:58 +01:00
cache_test.go Videos: Allow setting a lower TTL for caching video content #3631 2023-08-15 11:06:43 +02:00
color.go CI: Apply Go linter recommendations to "thumb" package #5330 2025-11-22 11:55:19 +01:00
color_test.go Config: Improve thumbnail generation option parsing and defaults #1474 2024-05-18 10:59:37 +02:00
config.go Thumbs: Update package config, add IccProfilesPath & ExamplesPath #5178 2025-08-28 15:39:12 +02:00
config_test.go Thumbs: Update package config, add IccProfilesPath & ExamplesPath #5178 2025-08-28 15:39:12 +02:00
create.go Videos: Refactor codec, content and file type specifications #4770 2025-02-05 00:30:45 +01:00
create_test.go Test: Use PascalCase names for all Go subtests in /internal 2025-10-02 14:50:02 +02:00
errors.go CI: Apply Go linter recommendations to "thumb" package #5330 2025-11-22 11:55:19 +01:00
fileinfo.go CI: Apply Go linter recommendations to "thumb" package #5330 2025-11-22 11:55:19 +01:00
fileinfo_test.go Config: Refactor command flags, reports, and client options 2025-04-15 15:42:03 +02:00
filter.go Thumbs: Update package config, add IccProfilesPath & ExamplesPath #5178 2025-08-28 15:39:12 +02:00
filter_test.go Backend: Improve Copy()/Move() and increase pkg/internal test coverage 2025-09-22 03:07:51 +02:00
fit.go Thumbs: Add "fit_5120" size suitable for Retina 5K displays #4810 2025-02-25 11:21:38 +01:00
fit_test.go Test: Use PascalCase names for all Go subtests in /internal 2025-10-02 14:50:02 +02:00
generator.go CI: Apply Go linter recommendations to "thumb" package #5330 2025-11-22 11:55:19 +01:00
icc.go Thumbs: Enhance embedding of ICC profiles based on InteropIndex #5178 2025-11-23 12:56:58 +01:00
icc_test.go Thumbs: Enhance embedding of ICC profiles based on InteropIndex #5178 2025-11-23 12:56:58 +01:00
init.go CI: Apply Go linter recommendations to "thumb" package #5330 2025-11-22 11:55:19 +01:00
init_test.go Test: Use PascalCase names for all Go subtests in /internal 2025-10-02 14:50:02 +02:00
jpeg.go Config: Improve thumbnail generation option parsing and defaults #1474 2024-05-18 10:59:37 +02:00
jpeg_test.go Test: Use PascalCase names for all Go subtests in /internal 2025-10-02 14:50:02 +02:00
memsize.go CI: Apply Go linter recommendations to "thumb" package #5330 2025-11-22 11:55:19 +01:00
memsize_test.go Backend: Improve Copy()/Move() and increase pkg/internal test coverage 2025-09-22 03:07:51 +02:00
names.go AI: Default to the 720x720 fit thumb for generating captions #3438 #5011 2025-07-16 14:58:44 +02:00
names_test.go Test: Use PascalCase names for all Go subtests in /internal 2025-10-02 14:50:02 +02:00
open.go Videos: Refactor codec, content and file type specifications #4770 2025-02-05 00:30:45 +01:00
open_jpeg.go CI: Apply Go linter recommendations to "thumb" package #5330 2025-11-22 11:55:19 +01:00
open_jpeg_test.go Test: Use PascalCase names for all Go subtests in /internal 2025-10-02 14:50:02 +02:00
open_test.go JPEG: Convert Apple "Display P3" colors to standard sRGB #1474 2021-12-09 07:00:39 +01:00
options.go CI: Apply Go linter recommendations to "thumb" package #5330 2025-11-22 11:55:19 +01:00
options_test.go Thumb: Skip left_224 and right_224 if the original is square #1474 2024-05-17 13:36:32 +02:00
png.go Thumbnails: Add panic handler for unexpected image encoding errors #3858 2023-10-31 14:37:47 +01:00
png_test.go Test: Use PascalCase names for all Go subtests in /internal 2025-10-02 14:50:02 +02:00
quality.go Thumbs: Update package config, add IccProfilesPath & ExamplesPath #5178 2025-08-28 15:39:12 +02:00
quality_test.go Test: Use PascalCase names for all Go subtests in /internal 2025-10-02 14:50:02 +02:00
README.md Thumbs: Improve README.md and inline docs in vips_icc.go #5178 2025-11-24 17:31:55 +01:00
report.go Backend: Move report package to /pkg/txt/report 2024-07-03 09:29:15 +02:00
report_test.go Thumbs: Update assertions in internal/thumb/report_test.go #4300 2024-05-29 10:16:03 +02:00
resample.go CI: Apply Go linter recommendations to "thumb" package #5330 2025-11-22 11:55:19 +01:00
rotate.go CI: Apply Go linter recommendations to "thumb" package #5330 2025-11-22 11:55:19 +01:00
size.go Config: Improve thumbnail generation option parsing and defaults #1474 2024-05-18 10:59:37 +02:00
size_test.go Thumbs: Add "fit_5120" size suitable for Retina 5K displays #4810 2025-02-25 11:21:38 +01:00
sizes.go CI: Apply Go linter recommendations to "thumb" package #5330 2025-11-22 11:55:19 +01:00
sizes_test.go Config: Improve thumbnail generation option parsing and defaults #1474 2024-05-18 10:59:37 +02:00
thumb.go CI: Apply Go linter recommendations to "thumb" package #5330 2025-11-22 11:55:19 +01:00
thumb_test.go TestMain: Handle "defer" before os.Exit #5330 2025-11-21 18:58:36 +01:00
video.go CI: Apply Go linter recommendations to "thumb" package #5330 2025-11-22 11:55:19 +01:00
video_test.go Thumb: Update supported sizes for videos and full screen viewer #1474 2024-05-17 15:07:27 +02:00
viewer.go Thumbs: Add "fit_5120" size suitable for Retina 5K displays #4810 2025-02-25 11:21:38 +01:00
viewer_test.go Thumbs: Add "fit_5120" size suitable for Retina 5K displays #4810 2025-02-25 11:21:38 +01:00
vips.go Vips: Only call GetString() if interop index exists #5389 2025-12-29 10:02:49 +01:00
vips_icc.go Vips: Skip all images that already have an ICC profile #5389 2025-12-29 10:14:13 +01:00
vips_icc_test.go Thumbs: Enhance embedding of ICC profiles based on InteropIndex #5178 2025-11-23 12:56:58 +01:00
vips_init.go CI: Apply Go linter recommendations to "thumb" package #5330 2025-11-22 11:55:19 +01:00
vips_init_test.go Thumbs: Configure max cache size and number of workers for libvips #1474 2024-05-16 10:34:53 +02:00
vips_rotate.go Backend: Improve Copy()/Move() and increase pkg/internal test coverage 2025-09-22 03:07:51 +02:00
vips_rotate_test.go Backend: Improve Copy()/Move() and increase pkg/internal test coverage 2025-09-22 03:07:51 +02:00
vips_test.go JPEG: Embed Adobe RGB ICC profile with an InteropIndex tag #5178 2025-11-23 10:07:30 +01:00

PhotoPrism — Thumbnails Package

Last Updated: November 24, 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 PhotoPrisms 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 — main Vips entry: load, resize/crop, strip metadata, export.
  • vips_icc.go — EXIF InteroperabilityIndex handling and ICC embedding.
  • icc.go — lists bundled ICC filenames (IccProfiles) and GetIccProfile helper.
  • resample.go, sizes.go — resample options and predefined sizes.
  • thumb.go and helpers — naming, caching, file info.
  • Tests live alongside sources (*_test.go, fixtures under testdata/).

ICC & Interop Handling

  • EXIF InteroperabilityIndex codes 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.
  • Exiftool name differs (libvips expects exif-ifd4-InteroperabilityIndex):
    exiftool -InteropIndex -InteropVersion -icc_profile:all -G -s file.jpg
    
  • 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-go or golangci-lint run ./internal/thumb/...

Notes

  • When adding ICC files, place them in assets/profiles/icc/ and append to IccProfiles.
  • Comments for exported identifiers must start with the identifier name (Go style).