crop

package
v0.0.0-...-6a2a004 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package crop provides image crop data structures and helpers.

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

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)
View Source
var Sizes = SizeMap{
	Tile50:  {Tile50, Tile320, "Lists", 50, 50, DefaultOptions},
	Tile100: {Tile100, Tile320, "Maps", 100, 100, DefaultOptions},
	Tile160: {Tile160, Tile320, "FaceNet", 160, 160, DefaultOptions},
	Tile224: {Tile224, Tile320, "TensorFlow, Mosaic", 224, 224, DefaultOptions},
	Tile320: {Tile320, "", "UI", 320, 320, DefaultOptions},
	Tile500: {Tile500, "", "FaceNet", 500, 500, DefaultOptions},
}

Sizes contains the properties of all thumbnail sizes.

Functions

func FileName

func FileName(hash, area string, width, height int, thumbPath string) (fileName string, err error)

FileName returns the crop file name based on cache path, size, and area.

func FileWidth

func FileWidth(area Area, size Size) int

FileWidth returns the minimal thumbnail width based on crop area and size.

func FromCache

func FromCache(hash, area string, size Size, thumbPath string) (fileName string, err error)

FromCache returns the crop file name if cached.

func FromRequest

func FromRequest(hash, area string, size Size, thumbPath string) (fileName string, err error)

FromRequest returns the crop file name for an image hash, and creates it if needed.

func ImageFromThumb

func ImageFromThumb(thumbName string, area Area, size Size, cache bool) (img image.Image, err error)

ImageFromThumb returns a cropped area from an existing thumbnail image.

func IsCroppedThumb

func IsCroppedThumb(thumb string) int

IsCroppedThumb tests if the string represents a cropped thumbnail and returns the split position if true.

func ParseThumb

func ParseThumb(thumb string) (fileHash, area string)

ParseThumb splits a thumbnail string into the crop area and file hash.

func ThumbFileName

func ThumbFileName(hash string, area Area, size Size, thumbPath string) (string, error)

ThumbFileName returns the ideal thumb file name.

Types

type Area

type Area struct {
	Name string  `json:"name,omitempty"`
	X    float32 `json:"x,omitempty"`
	Y    float32 `json:"y,omitempty"`
	W    float32 `json:"w,omitempty"`
	H    float32 `json:"h,omitempty"`
}

Area represents a relative crop area.

func AreaFromString

func AreaFromString(s string) Area

AreaFromString returns an image area.

func NewArea

func NewArea(name string, x, y, w, h float32) Area

NewArea returns new relative image area.

func (Area) Bottom

func (a Area) Bottom() float64

Bottom returns the bottom Y coordinate as float64.

func (Area) Bounds

func (a Area) Bounds(img image.Image) (min, max image.Point, dim int)

Bounds returns absolute coordinates and dimension.

func (Area) Empty

func (a Area) Empty() bool

Empty tests if the area is empty.

func (Area) FileWidth

func (a Area) FileWidth(size Size) int

FileWidth returns the ideal file width based on the crop size.

func (Area) Left

func (a Area) Left() float64

Left returns the left X coordinate as float64.

func (Area) Overlap

func (a Area) Overlap(other Area) (x, y float64)

Overlap calculates the overlap of two areas.

func (Area) OverlapArea

func (a Area) OverlapArea(other Area) (area float64)

OverlapArea calculates the overlap area of two areas.

func (Area) OverlapPercent

func (a Area) OverlapPercent(other Area) int

OverlapPercent calculates the overlap ratio of two areas in percent.

func (Area) Right

func (a Area) Right() float64

Right returns the right X coordinate as float64.

func (Area) String

func (a Area) String() string

String returns a string identifying the crop area.

func (Area) Surface

func (a Area) Surface() float64

Surface returns the surface area.

func (Area) SurfaceRatio

func (a Area) SurfaceRatio(area float64) float64

SurfaceRatio returns the surface ratio.

func (Area) Thumb

func (a Area) Thumb(fileHash string) string

Thumb returns a string identifying the file and crop area to create a thumb.

func (Area) Top

func (a Area) Top() float64

Top returns the top Y coordinate as float64.

type Areas

type Areas []Area

Areas represents a list of relative crop areas.

type Name

type Name string

Name represents a crop size name.

const (
	Tile50  Name = "tile_50"
	Tile100 Name = "tile_100"
	Tile160 Name = "tile_160"
	Tile224 Name = "tile_224"
	Tile320 Name = "tile_320"
	Tile500 Name = "tile_500"
)

Names of standard crop sizes.

func (Name) Jpeg

func (n Name) Jpeg() string

Jpeg returns the crop name with a jpeg file extension suffix as string.

type Size

type Size struct {
	Name    Name                   `json:"name"`
	Source  Name                   `json:"-"`
	Use     string                 `json:"use"`
	Width   int                    `json:"w"`
	Height  int                    `json:"h"`
	Options []thumb.ResampleOption `json:"-"`
}

type SizeMap

type SizeMap map[Name]Size

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL