img

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func TransformFile

func TransformFile(source string, destinations map[string]Options) error
Example
sourceImg := "../assets/leica.jpg"
homeDir, _ := os.UserHomeDir()
sourceDir := path.Join(homeDir, "transform")
_ = os.Mkdir(sourceDir, 0755)

//for all but the thumb we are copying the original meta information
thumb := NewOptions(ResizeAndCrop, 400, 400, false)
landscape := NewOptions(ResizeAndCrop, 1200, 628, true)
square := NewOptions(ResizeAndCrop, 1200, 1200, true)
portrait := NewOptions(ResizeAndCrop, 1080, 1350, true)
resize := NewOptions(Resize, 1200, 0, true)

destImgs := map[string]Options{
	path.Join(sourceDir, "thumb.jpg"):     thumb,
	path.Join(sourceDir, "landscape.jpg"): landscape,
	path.Join(sourceDir, "square.jpg"):    square,
	path.Join(sourceDir, "portrait.jpg"):  portrait,
	path.Join(sourceDir, "resize.jpg"):    resize,
}

_ = TransformFile(sourceImg, destImgs)
fmt.Println("Transformed leica.jpg")
Output:

Transformed leica.jpg

Types

type CropAnchor

type CropAnchor int
const (
	Center CropAnchor = iota
	TopLeft
	Top
	TopRight
	Left
	Right
	BottomLeft
	Bottom
	BottomRight
)

type Options

type Options struct {
	Width     int
	Height    int
	Quality   int
	Anchor    CropAnchor
	Transform TransformType
	Strategy  ResampleStrategy
	CopyExif  bool
}

func NewOptions

func NewOptions(transform TransformType, width, height int, copyExif bool) Options

Create Options that default to crop center strategy, image quality 90% and Resize strategy lanczos

type ResampleStrategy

type ResampleStrategy int
const (
	Lanczos ResampleStrategy = iota
	NearestNeighbor
	Box
	Linear
	Hermite
	MitchellNetravali
	CatmullRom
	BSpline
	Gaussian
	Bartlett
	Hann
	Hamming
	Blackman
	Welch
	Cosine
)

type TransformType

type TransformType int
const (
	//Scales the image to given dimension. To keep aspect ratio the image is cropped
	ResizeAndCrop TransformType = iota
	//Cuts a specified region of the image
	Crop
	//Scale the image to the specified dimensions. To keep aspect ratio set either width or height to 0
	Resize
	//Scale the image to fit the maximum specified dimensions.
	ResizeAndFit
)

Jump to

Keyboard shortcuts

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