bild: github.com/anthonynsimon/bild/transform Index | Files

package transform

import "github.com/anthonynsimon/bild/transform"

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

Package Files

filters.go resize.go rotate.go shear.go translate.go

func Crop Uses

func Crop(img image.Image, rect image.Rectangle) *image.RGBA

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 FlipH Uses

func FlipH(img image.Image) *image.RGBA

FlipH returns a horizontally flipped version of the image.

func FlipV Uses

func FlipV(img image.Image) *image.RGBA

FlipV returns a vertically flipped version of the image.

func Resize Uses

func Resize(img image.Image, width, height int, filter ResampleFilter) *image.RGBA

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 Uses

func Rotate(img image.Image, angle float64, options *RotationOptions) *image.RGBA

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 Uses

func ShearH(img image.Image, angle float64) *image.RGBA

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 Uses

func ShearV(img image.Image, angle float64) *image.RGBA

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 Uses

func Translate(img image.Image, dx, dy int) *image.RGBA

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.

type ResampleFilter Uses

type ResampleFilter struct {
    Support float64
    Fn      func(x float64) float64
}

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 Uses

type RotationOptions struct {
    ResizeBounds bool
    Pivot        *image.Point
}

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.

Package transform imports 5 packages (graph) and is imported by 4 packages. Updated 2017-02-01. Refresh now. Tools for package owners.