Documentation ¶
Overview ¶
Package transform provides basic image transformation functions, such as resizing, rotation and flipping. It includes a variety of resampling filters to handle interpolation in case that upsampling or downsampling is required.
Index ¶
- func Crop(img image.Image, rect image.Rectangle) *image.RGBA
- func FlipH(img image.Image) *image.RGBA
- func FlipV(img image.Image) *image.RGBA
- func Resize(img image.Image, width, height int, filter ResampleFilter) *image.RGBA
- func Rotate(img image.Image, angle float64, options *RotationOptions) *image.RGBA
- func ShearH(img image.Image, angle float64) *image.RGBA
- func ShearV(img image.Image, angle float64) *image.RGBA
- func Translate(img image.Image, dx, dy int) *image.RGBA
- type ResampleFilter
- type RotationOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Crop ¶
Crop returns a new image which contains the intersection between the rect and the image provided as params. Only the intersection is returned. If a rect larger than the image is provided, no fill is done to the 'empty' area.
Usage example:
result := bild.Crop(img, image.Rect(0,0,512,256))
func Resize ¶
Resize returns a new image with its size adjusted to the new width and height. The filter param corresponds to the Resampling Filter to be used when interpolating between the sample points.
Usage example:
result := bild.Resize(img, 800, 600, bild.Linear)
func Rotate ¶
Rotate returns a rotated image by the provided angle using the pivot as an anchor. Parameters angle is in degrees and it's applied clockwise. Default parameters are used if a nil *RotationOptions is passed.
Usage example:
// Rotate 90.0 degrees clockwise, preserving the image size and the pivot point at the top left corner result := bild.Rotate(img, 90.0, &bild.RotationOptions{PreserveSize: true, Pivot: &image.Point{0, 0}})
func ShearH ¶ added in v0.7.0
ShearH applies a shear linear transformation along the horizontal axis, the parameter angle is the shear angle to be applied. The transformation will be applied with the center of the image as the pivot.
func ShearV ¶ added in v0.7.0
ShearV applies a shear linear transformation along the vertical axis, the parameter angle is the shear angle to be applied. The transformation will be applied with the center of the image as the pivot.
func Translate ¶ added in v0.9.0
Translate repositions a copy of the provided image by dx on the x-axis and by dy on the y-axis and returns the result. The bounds from the provided image will be kept. A positive dx value moves the image towards the right and a positive dy value moves the image upwards.
Types ¶
type ResampleFilter ¶
ResampleFilter is used to evaluate sample points and interpolate between them. Support is the number of points required by the filter per 'side'. For example, a support of 1.0 means that the filter will get pixels on positions -1 and +1 away from it. Fn is the resample filter function to evaluate the samples.
var Box ResampleFilter
Box resampling filter, only let pass values in the x < 0.5 range from sample. It produces similar results to the Nearest Neighbor method.
var CatmullRom ResampleFilter
CatmullRom resampling filter interpolates between the four nearest samples per dimension.
var Gaussian ResampleFilter
Gaussian resampling filter interpolates using a Gaussian function between the two nearest samples per dimension.
var Lanczos ResampleFilter
Lanczos resampling filter interpolates between the six nearest samples per dimension.
var Linear ResampleFilter
Linear resampling filter interpolates linearly between the two nearest samples per dimension.
var MitchellNetravali ResampleFilter
MitchellNetravali resampling filter interpolates between the four nearest samples per dimension.
var NearestNeighbor ResampleFilter
NearestNeighbor resampling filter assigns to each point the sample point nearest to it.
type RotationOptions ¶
RotationOptions are the rotation parameters ResizeBounds set to false will keep the original image bounds, cutting any pixels that go past it when rotating. Pivot is the point of anchor for the rotation. Default of center is used if a nil is passed. If ResizeBounds is set to true, a center pivot will always be used.