Documentation ¶
Overview ¶
Package imageutil image utils func
Index ¶
- Variables
- func ColorFromHex(hexColor string) color.RGBA
- func DrawLabel(img *image.RGBA, font *Font, label string, pt image.Point, txtColor string, ...)
- func DrawRectangle(img *image.RGBA, bounds image.Rectangle, borderColor string, bgColor string, ...)
- func ImageToRGBA(img image.Image) *image.RGBA
- func IsHex(s string) bool
- func NewFontCache(fontFolder string) *draw2d.SyncFolderFontCache
- func NormalizeImage(img image.Image, maxSize int) image.Image
- func Resample(img image.Image, width, height int, opts ...ResampleOption) image.Image
- func Thumb(img image.Image, area Area, size Size) image.Image
- type Area
- func (a Area) Bottom() float64
- func (a Area) Bounds(img image.Image) (min, max image.Point, dim int)
- func (a Area) Empty() bool
- func (a Area) Left() float64
- func (a Area) Overlap(other Area) (x, y float64)
- func (a Area) OverlapArea(other Area) (area float64)
- func (a Area) OverlapPercent(other Area) int
- func (a Area) Right() float64
- func (a Area) String() string
- func (a Area) Surface() float64
- func (a Area) SurfaceRatio(area float64) float64
- func (a Area) Top() float64
- type Areas
- type Font
- type Name
- type ResampleFilter
- type ResampleOption
- type Size
- type SizeMap
Constants ¶
This section is empty.
Variables ¶
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 )
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 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 ¶
ImageToRGBA conver image.Image to *image.RGBA
func IsHex ¶
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 ¶
NormalizeImage resize image to 640x640
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 (Area) OverlapArea ¶
OverlapArea calculates the overlap area of two areas.
func (Area) OverlapPercent ¶
OverlapPercent calculates the overlap ratio of two areas in percent.
func (Area) SurfaceRatio ¶
SurfaceRatio returns the surface ratio.
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
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.
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 ¶
func (a ResampleFilter) Imaging() imaging.ResampleFilter
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 .