Documentation
¶
Index ¶
- func CropImage(img image.Image, crop image.Rectangle) image.Image
- func Open(fileName string) (image.Image, error)
- func OpenOpts(fileName string, autoOrientation bool, srcBytes bool) (image.Image, []byte, error)
- func RotateAndCropFile(source string, dest string, opts Options) error
- func RotateImage(img image.Image, angle int) image.Image
- func Save(image image.Image, fileName string) error
- func SaveOpts(image image.Image, fileName string, quality int, srcExif []byte) error
- func TransformFile(source string, destinations map[string]Options) error
- type CropAnchor
- type Options
- type ResampleStrategy
- type TransformType
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OpenOpts ¶ added in v0.0.11
OpenOpts opens an Image for editing. Possibly returning the src file as a byte slice
func RotateAndCropFile ¶ added in v0.0.11
RotateAndCropFile rotates and crops an image file and saves the result
func RotateImage ¶ added in v0.0.11
RotateImage rotates an image. Negative angle indicates a counter clockwise rotation
func SaveOpts ¶ added in v0.0.11
SaveOpts saves an image. If srcExif is != nil it will try to extract and exif information from that and append it to the new file
func TransformFile ¶
TransformFile creates versions of source based on destinations
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
CropAnchor specifies where the anchor point should be when cropping an image
const ( Center CropAnchor = iota TopLeft Top TopRight Left Right BottomLeft Bottom BottomRight )
Various Anchors for your crop
type Options ¶
type Options struct {
Width int
Height int
Quality int
Anchor CropAnchor
Transform TransformType
Strategy ResampleStrategy
X int
Y int
Angle int
CopyExif bool
}
Options holds all options for a given image transformation job
func NewOptions ¶
func NewOptions(transform TransformType, width, height int, copyExif bool) Options
NewOptions creates Options that default to crop center strategy, image quality 90% and Resize strategy lanczos
type ResampleStrategy ¶
type ResampleStrategy int
ResampleStrategy specifies what method to use when resampling an image
const ( //Lanczos sampling. Default Lanczos ResampleStrategy = iota //NearestNeighbor sampling NearestNeighbor //Box sampling Box //Linear sampling Linear //Hermite sampling Hermite //MitchellNetravali sampling MitchellNetravali //CatmullRom sampling CatmullRom //BSpline sampling BSpline //Gaussian sampling Gaussian //Bartlett sampling Bartlett //Hann sampling Hann //Hamming sampling Hamming //Blackman sampling Blackman //Welch sampling Welch //Cosine sampling Cosine )
type TransformType ¶
type TransformType int
TransformType specifies how to transform an image, crop, resize, etc...
const ( //ResizeAndCrop scales the image to given dimension. To keep aspect ratio the image is cropped ResizeAndCrop TransformType = iota //Crop cuts a specified region of the image Crop //Resize scale the image to the specified dimensions. To keep aspect ratio set either width or height to 0 Resize //ResizeAndFit scale the image to fit the maximum specified dimensions. ResizeAndFit )