paint

package
v0.0.0-...-3570e06 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddResizer

func AddResizer(resizeType ResizeType, resizer Resizer)

AddResizer allows a custom resizer to use

func GetAvailableTypes

func GetAvailableTypes() map[ResizeType]ResizeType

GetAvailableTypes returns all available types

func GetCustomResizers

func GetCustomResizers() map[ResizeType]Resizer

GetCustomResizers returns a read only list of custom resizers

Types

type Controller

type Controller interface {
	Encode(target io.Writer) error
	Resize(resizeType ResizeType, width, height int) error
	Image() image.Image
	Format() string
}

Controller lets you completely control one image

func NewController

func NewController(data io.Reader, customResizers map[ResizeType]Resizer) (Controller, error)

NewController returns a new instance of a basic controller

type CropResizer

type CropResizer struct {
}

CropResizer scales the image down, and crops it to the given width and height

func (CropResizer) Resize

func (c CropResizer) Resize(input image.Image, dstWidth, dstHeight int) (image.Image, error)

Resize with mode crop. Does the acutal resizing and returns the image errors only if dstWidth or dstHeight is invalid

type FitResizer

type FitResizer struct {
}

FitResizer fits the original image into the given bounding box by keeping the original ratio

func (FitResizer) Resize

func (f FitResizer) Resize(input image.Image, dstWidth, dstHeight int) (image.Image, error)

Resize with mode fit. Does the acutal resizing and returns the image errors only if dstWidth or dstHeight is invalid

type PlainResizer

type PlainResizer struct {
}

PlainResizer resizes to the given width and height, regardless of the previous image properties

func (PlainResizer) Resize

func (p PlainResizer) Resize(input image.Image, dstWidth, dstHeight int) (image.Image, error)

Resize with mode plain. Does the acutal resizing and returns the image errors only if dstWidth or dstHeight is invalid

type ResizeType

type ResizeType string

ResizeType defines which image manipulation will or can be used each ResizeType has its corresponding Resizer

const (
	//TypeResize will either force the given sizes, or resize via original ratio when either height or width is not specified
	TypeResize ResizeType = "resize"
	//TypeCrop will generate an image with exact sizes, but only a part of the image is visible
	TypeCrop ResizeType = "crop"
	//TypeFit will resize the image according to the original ratio, but will not exceed the given bounds
	TypeFit ResizeType = "fit"
)

type Resizer

type Resizer interface {
	Resize(input image.Image, dstWidth, dstHeight int) (image.Image, error)
}

Resizer can resize an image dstWidth and dstHeight are the desired output values but it is not promised that the output image has exactly those bounds

Jump to

Keyboard shortcuts

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