- 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.
12 lines
242 B
Go
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})
|
|
}
|