Vellum/internal/modules/photos/encode.go
mithral 0212d089ec Phase 6c: photo thumbnails and viewer
- photos: generates a downscaled JPEG thumbnail per image, because serving a
  folder of 12-megapixel originals to a grid is unusable on a TV box. Uses
  CatmullRom scaling via golang.org/x/image; decodes jpeg/png/gif/webp.
- an undecodable format returns no thumbnail rather than an error, so the grid
  falls back to a placeholder.
- images already smaller than the 512px ceiling are passed through untouched.
- library items endpoint now returns library_id, which the viewer needs to
  find its siblings for navigation.
- web: PhotoViewer with keyboard and button navigation within the library.

Verified: 900x1200 PNG thumbnailed to a 512-long-edge JPEG and served;
unit tests assert exact dimensions, aspect preservation, and that non-images
produce no thumbnail without erroring.
2026-10-09 21:22:30 -04:00

12 lines
242 B
Go

package photos
import (
"image"
"image/jpeg"
"io"
)
// encodeJPEG writes an image as JPEG at a quality suited to thumbnails.
func encodeJPEG(w io.Writer, img image.Image) error {
return jpeg.Encode(w, img, &jpeg.Options{Quality: 82})
}