imageutil

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package imageutil image utils func

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultResampleOptions represents default resample options
	DefaultResampleOptions = []ResampleOption{ResampleFillCenter, ResampleDefault}
	// DefaultResampleFitOptions represents default resample fit options
	DefaultResampleFitOptions = []ResampleOption{ResampleFit, ResampleDefault}
	// Filter represents default resample filter
	Filter = ResampleLanczos
)
View Source
var Sizes = SizeMap{
	Tile50:  {Tile50, Tile320, "Lists", 50, 50, DefaultResampleOptions},
	Tile100: {Tile100, Tile320, "Maps", 100, 100, DefaultResampleOptions},
	Tile160: {Tile160, Tile320, "FaceNet", 160, 160, DefaultResampleOptions},
	Tile224: {Tile224, Tile320, "TensorFlow, Mosaic", 224, 224, DefaultResampleOptions},
	Tile320: {Tile320, "", "UI", 320, 320, DefaultResampleOptions},
	Tile500: {Tile500, "", "FaceNet", 500, 500, DefaultResampleOptions},
	Fit720:  {Fit720, "", "Mobile, TV", 720, 720, DefaultResampleFitOptions},
	Fit1280: {Fit1280, Fit2048, "Mobile, HD Ready TV", 1280, 1024, DefaultResampleFitOptions},
	Fit1920: {Fit1920, Fit2048, "Mobile, Full HD TV", 1920, 1200, DefaultResampleFitOptions},
	Fit2048: {Fit2048, "", "Tablets, Cinema 2K", 2048, 2048, DefaultResampleFitOptions},
	Fit2560: {Fit2560, "", "Quad HD, Retina Display", 2560, 1600, DefaultResampleFitOptions},
	Fit3840: {Fit3840, "", "Ultra HD", 3840, 2400, DefaultResampleFitOptions},
	Fit4096: {Fit4096, "", "Ultra HD, Retina 4K", 4096, 4096, DefaultResampleFitOptions},
	Fit7680: {Fit7680, "", "8K Ultra HD 2, Retina 6K", 7680, 4320, DefaultResampleFitOptions},
}

Sizes contains the properties of all thumbnail sizes.

Functions

func ColorFromHex

func ColorFromHex(hexColor string) color.RGBA

ColorFromHex get color from hex

func DrawLabel

func DrawLabel(img *image.RGBA, font *Font, label string, pt image.Point, txtColor string, bgColor string, scale float64)

DrawLabel draw label text to image

func DrawRectangle

func DrawRectangle(img *image.RGBA, bounds image.Rectangle, borderColor string, bgColor string, strokeWidth float64)

DrawRectangle draw rectangle on image

func ImageToRGBA

func ImageToRGBA(img image.Image) *image.RGBA

ImageToRGBA conver image.Image to *image.RGBA

func IsHex

func IsHex(s string) bool

IsHex returns true if the string only contains hex numbers, dashes and letters without whitespace.

func NewFontCache

func NewFontCache(fontFolder string) *draw2d.SyncFolderFontCache

NewFontCache load font cache

func NormalizeImage

func NormalizeImage(img image.Image, maxSize int) image.Image

NormalizeImage resize image to 640x640

func Resample

func Resample(img image.Image, width, height int, opts ...ResampleOption) image.Image

Resample downscales an image and returns it.

func Thumb

func Thumb(img image.Image, area Area, size Size) image.Image

Thumb returns a cropped area from an existing thumbnail image.

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) 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) 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 Font

type Font struct {
	// Cache FontCache
	Cache draw2d.FontCache
	// Size font size
	Size float64 `json:"size,omitempty"`
	// Data font setting
	Data *draw2d.FontData `json:"data,omitempty"`
	// Font
	Font *truetype.Font `json:"-"`
}

Font font info

func (*Font) Load

func (f *Font) Load(cache draw2d.FontCache) error

Load font from font cache

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"
	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 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 ResampleFilter

type ResampleFilter string

ResampleFilter represents resample filter

const (
	// ResampleBlackman .
	ResampleBlackman ResampleFilter = "blackman"
	// ResampleLanczos .
	ResampleLanczos ResampleFilter = "lanczos"
	// ResampleCubic .
	ResampleCubic ResampleFilter = "cubic"
	// ResampleLinear .
	ResampleLinear ResampleFilter = "linear"
)

func (ResampleFilter) Imaging

Imaging returns resample filter

type ResampleOption

type ResampleOption int

ResampleOption represents resample option

const (
	// ResampleFillCenter .
	ResampleFillCenter ResampleOption = iota
	// ResampleFillTopLeft .
	ResampleFillTopLeft
	// ResampleFillBottomRight .
	ResampleFillBottomRight
	// ResampleFit .
	ResampleFit
	// ResampleResize .
	ResampleResize
	// ResampleNearestNeighbor .
	ResampleNearestNeighbor
	// ResampleDefault .
	ResampleDefault
	// ResamplePng .
	ResamplePng
)

func ResampleOptions

func ResampleOptions(opts ...ResampleOption) (method ResampleOption, filter imaging.ResampleFilter)

ResampleOptions extracts filter, format, and method from resample options.

type Size

type Size struct {
	// Name size name
	Name Name `json:"name"`
	// Source size source
	Source Name `json:"-"`
	// Use size usage
	Use string `json:"use"`
	// Width size width
	Width int `json:"w"`
	// Height size height
	Height int `json:"h"`
	// Options resample options
	Options []ResampleOption `json:"-"`
}

Size .

type SizeMap

type SizeMap map[Name]Size

SizeMap size map

Jump to

Keyboard shortcuts

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