Documentation ¶
Overview ¶
Package thumb provides JPEG resampling and thumbnail generation.
Copyright (c) 2018 - 2024 PhotoPrism UG. All rights reserved.
This program is free software: you can redistribute it and/or modify it under Version 3 of the GNU Affero General Public License (the "AGPL"): <https://docs.photoprism.app/license/agpl> This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. The AGPL is supplemented by our Trademark and Brand Guidelines, which describe how our Brand Assets may be used: <https://www.photoprism.app/trademark>
Feel free to send an email to hello@photoprism.app if you have questions, want to support our work, or just want to say hello.
Additional information can be found in our Developer Guide: <https://docs.photoprism.app/developer-guide/>
Index ¶
- Constants
- Variables
- func Create(img image.Image, fileName string, width, height int, opts ...ResampleOption) (result image.Image, err error)
- func FileName(hash, thumbPath string, width, height int, opts ...ResampleOption) (fileName string, err error)
- func Find(limit int) (name Name, size Size)
- func FromCache(imageFilename, hash, thumbPath string, width, height int, ...) (fileName string, err error)
- func FromFile(imageFilename, hash, thumbPath string, width, height, orientation int, ...) (fileName string, err error)
- func InvalidSize(size int) bool
- func Jpeg(srcFile, jpgFile string, orientation int) (img image.Image, err error)
- func MaxSize() int
- func Open(fileName string, orientation int) (result image.Image, err error)
- func OpenJpeg(fileName string, orientation int) (image.Image, error)
- func Png(srcFile, pngFile string, orientation int) (img image.Image, err error)
- func Report(sizes SizeList, short bool) (rows [][]string, cols []string)
- func Resample(img image.Image, width, height int, opts ...ResampleOption) image.Image
- func ResolvedName(hash, thumbPath string, width, height int, opts ...ResampleOption) (fileName string, err error)
- func Rotate(img image.Image, o int) image.Image
- func Suffix(width, height int, opts ...ResampleOption) (result string)
- func Url(h, name, contentUri, previewToken string) string
- type Bytes
- type Name
- type Public
- type Quality
- type ResampleFilter
- type ResampleOption
- type Size
- func (s Size) Bounds() image.Rectangle
- func (s Size) Create(img image.Image, fileName string) (image.Image, error)
- func (s Size) ExceedsLimit() bool
- func (s Size) FileName(hash, thumbPath string) (string, error)
- func (s Size) FromCache(fileName, fileHash, cachePath string) (string, error)
- func (s Size) FromFile(fileName, fileHash, cachePath string, fileOrientation int) (string, error)
- func (s Size) ResolvedName(hash, thumbPath string) (string, error)
- func (s Size) Skip(img image.Image) bool
- func (s Size) Uncached() bool
- type SizeList
- type SizeMap
- type Thumb
Constants ¶
const ( KB = 1024 MB = KB * 1024 GB = MB * 1024 )
Byte size factors.
const ( OrientationUnspecified int = 0 OrientationNormal = 1 OrientationFlipH = 2 OrientationRotate180 = 3 OrientationFlipV = 4 OrientationTranspose = 5 OrientationRotate270 = 6 OrientationTransverse = 7 OrientationRotate90 = 8 )
Variables ¶
var ( JpegQuality = QualityDefault JpegQualitySmall = QualityLow )
Current Quality settings.
var ( SizePrecached = 2048 SizeUncached = 7680 Filter = ResampleLanczos )
var ( SizeTile50 = Size{Tile50, Tile500, "List View", 50, 50, false, false, []ResampleOption{ResampleFillCenter, ResampleDefault}} SizeTile100 = Size{Tile100, Tile500, "Places View", 100, 100, false, false, []ResampleOption{ResampleFillCenter, ResampleDefault}} SizeTile224 = Size{Tile224, Tile500, "TensorFlow, Mosaic View", 224, 224, false, false, []ResampleOption{ResampleFillCenter, ResampleDefault}} SizeTile500 = Size{Tile500, "", "Cards View", 500, 500, false, false, []ResampleOption{ResampleFillCenter, ResampleDefault}} SizeColors = Size{Colors, Fit720, "Color Detection", 3, 3, false, false, []ResampleOption{ResampleResize, ResampleNearestNeighbor, ResamplePng}} SizeLeft224 = Size{Left224, Fit720, "TensorFlow", 224, 224, false, false, []ResampleOption{ResampleFillTopLeft, ResampleDefault}} SizeRight224 = Size{Right224, Fit720, "TensorFlow", 224, 224, false, false, []ResampleOption{ResampleFillBottomRight, ResampleDefault}} )
var (
CachePublic = false
)
var (
ErrNotCached = errors.New("not cached")
)
var FitSizes = SizeList{ Sizes[Fit7680], Sizes[Fit4096], Sizes[Fit3840], Sizes[Fit2560], Sizes[Fit2048], Sizes[Fit1920], Sizes[Fit1280], Sizes[Fit720], }
FitSizes contains "fit" cropped thumbnail sizes from largest to smallest. Best for the viewer as proportional resizing maintains the aspect ratio.
var Names = []Name{ Fit7680, Fit4096, Fit3840, Fit2560, Fit2048, Fit1920, Fit1280, Fit720, Right224, Left224, Colors, Tile500, Tile224, Tile100, Tile50, }
Names contains all default size names.
var QualityLevels = map[string]Quality{ "5": QualityBest, "ultra": QualityBest, "best": QualityBest, "4": QualityHigh, "excellent": QualityHigh, "good": QualityHigh, "high": QualityHigh, "3": QualityDefault, "": QualityDefault, "ok": QualityDefault, "default": QualityDefault, "standard": QualityDefault, "medium": QualityDefault, "2": QualityLow, "low": QualityLow, "small": QualityLow, "1": QualityBad, "bad": QualityBad, "0": QualityWorst, "worst": QualityWorst, "lowest": QualityWorst, }
QualityLevels maps human-readable settings to a numeric Quality.
var ResampleMethods = map[ResampleOption]string{ ResampleFillCenter: "center", ResampleFillTopLeft: "left", ResampleFillBottomRight: "right", ResampleFit: "fit", ResampleResize: "resize", }
var Sizes = SizeMap{ Tile50: SizeTile50, Tile100: SizeTile100, Tile224: SizeTile224, Tile500: SizeTile500, Colors: SizeColors, Left224: SizeLeft224, Right224: SizeRight224, Fit720: {Fit720, "", "SD TV, Mobile", 720, 720, true, true, []ResampleOption{ResampleFit, ResampleDefault}}, Fit1280: {Fit1280, Fit2048, "HD TV, SXGA", 1280, 1024, true, true, []ResampleOption{ResampleFit, ResampleDefault}}, Fit1920: {Fit1920, Fit2048, "Full HD", 1920, 1200, true, true, []ResampleOption{ResampleFit, ResampleDefault}}, Fit2048: {Fit2048, "", "DCI 2K, Tablets", 2048, 2048, true, true, []ResampleOption{ResampleFit, ResampleDefault}}, Fit2560: {Fit2560, "", "Quad HD, Notebooks", 2560, 1600, true, true, []ResampleOption{ResampleFit, ResampleDefault}}, Fit3840: {Fit3840, "", "4K Ultra HD", 3840, 2400, true, true, []ResampleOption{ResampleFit, ResampleDefault}}, Fit4096: {Fit4096, "", "DCI 4K, Retina 4K", 4096, 4096, true, true, []ResampleOption{ResampleFit, ResampleDefault}}, Fit7680: {Fit7680, "", "8K Ultra HD 2", 7680, 4320, true, true, []ResampleOption{ResampleFit, ResampleDefault}}, }
Sizes contains the properties of all thumbnail sizes.
var StandardRGB = true
StandardRGB configures whether colors in the Apple Display P3 color space should be converted to standard RGB.
var VideoSizes = SizeList{ Sizes[Fit7680], Sizes[Fit4096], Sizes[Fit3840], Sizes[Fit2560], Sizes[Fit2048], Sizes[Fit1920], Sizes[Fit1280], Sizes[Fit720], }
VideoSizes contains all valid video output sizes sorted by size.
Functions ¶
func Create ¶
func Create(img image.Image, fileName string, width, height int, opts ...ResampleOption) (result image.Image, err error)
Create creates an image thumbnail.
func FileName ¶
func FileName(hash, thumbPath string, width, height int, opts ...ResampleOption) (fileName string, err error)
FileName returns the file name of the thumbnail for the matching size.
func FromCache ¶
func FromCache(imageFilename, hash, thumbPath string, width, height int, opts ...ResampleOption) (fileName string, err error)
FromCache returns the filename if a thumbnail image with the matching size is in the cache.
func FromFile ¶
func FromFile(imageFilename, hash, thumbPath string, width, height, orientation int, opts ...ResampleOption) (fileName string, err error)
FromFile creates a new thumbnail with the specified size if it was not found in the cache, and returns the filename.
func InvalidSize ¶
InvalidSize tests if the size in pixels is invalid.
func OpenJpeg ¶
OpenJpeg loads a JPEG image from disk, rotates it, and converts the color profile if necessary.
func ResolvedName ¶
func ResolvedName(hash, thumbPath string, width, height int, opts ...ResampleOption) (fileName string, err error)
ResolvedName returns the file name of the thumbnail for the matching size with all symlinks resolved.
func Suffix ¶
func Suffix(width, height int, opts ...ResampleOption) (result string)
Suffix returns the thumb cache file suffix.
Types ¶
type Bytes ¶
type Bytes uint64
Bytes represents memory usage in bytes.
type Name ¶
type Name string
Name represents a thumbnail size name.
const ( Tile50 Name = "tile_50" Tile100 Name = "tile_100" Tile224 Name = "tile_224" Tile500 Name = "tile_500" Colors Name = "colors" Left224 Name = "left_224" Right224 Name = "right_224" Fit720 Name = "fit_720" Fit1280 Name = "fit_1280" Fit1920 Name = "fit_1920" Fit2048 Name = "fit_2048" Fit2560 Name = "fit_2560" Fit3840 Name = "fit_3840" Fit4096 Name = "fit_4096" Fit7680 Name = "fit_7680" )
Names of thumbnail sizes.
type Public ¶
type Public struct { Fit720 Thumb `json:"fit_720"` Fit1280 Thumb `json:"fit_1280"` Fit1920 Thumb `json:"fit_1920"` Fit2048 Thumb `json:"fit_2048"` Fit2560 Thumb `json:"fit_2560"` Fit3840 Thumb `json:"fit_3840"` Fit4096 Thumb `json:"fit_4096"` Fit7680 Thumb `json:"fit_7680"` }
Public represents public thumbnail URLs with dimensions.
type Quality ¶
type Quality int
Quality represents a JPEG image quality.
const ( QualityBest Quality = 95 QualityHigh Quality = 92 QualityDefault Quality = 85 QualityLow Quality = 80 QualityBad Quality = 75 QualityWorst Quality = 70 )
Common Quality levels. see https://docs.photoprism.app/user-guide/settings/advanced/#jpeg-quality
func ParseQuality ¶
ParseQuality returns the matching quality based on a config value string.
func (Quality) EncodeOption ¶
func (q Quality) EncodeOption() imaging.EncodeOption
EncodeOption returns the quality as imaging.EncodeOption.
type ResampleFilter ¶
type ResampleFilter string
const ( ResampleBlackman ResampleFilter = "blackman" ResampleLanczos ResampleFilter = "lanczos" ResampleCubic ResampleFilter = "cubic" ResampleLinear ResampleFilter = "linear" )
func (ResampleFilter) Imaging ¶
func (a ResampleFilter) Imaging() imaging.ResampleFilter
type ResampleOption ¶
type ResampleOption int
const ( ResampleFillCenter ResampleOption = iota ResampleFillTopLeft ResampleFillBottomRight ResampleFit ResampleResize ResampleNearestNeighbor ResampleDefault ResamplePng )
func ResampleOptions ¶
func ResampleOptions(opts ...ResampleOption) (method ResampleOption, filter imaging.ResampleFilter, format fs.Type)
ResampleOptions extracts filter, format, and method from resample options.
type Size ¶
type Size struct { Name Name `json:"name"` Source Name `json:"-"` Usage string `json:"usage"` Width int `json:"w"` Height int `json:"h"` Public bool `json:"-"` Fit bool `json:"-"` Options []ResampleOption `json:"-"` }
Size represents a standard media resolution.
func (Size) Create ¶
Create creates a thumbnail with the matching size and returns it as image.Image.
func (Size) ExceedsLimit ¶
ExceedsLimit tests if thumbnail type is too large, and can not be rendered at all.
func (Size) FromCache ¶
FromCache returns the filename if a thumbnail image with the matching size is in the cache.
func (Size) FromFile ¶
FromFile creates a new thumbnail with the matching size if it was not found in the cache, and returns the filename.
func (Size) ResolvedName ¶
ResolvedName returns the file name of the thumbnail for the matching size with all symlinks resolved.