transform

package
v0.0.0-...-358a119 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2020 License: MIT Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Crop

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

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

FlipH returns a horizontally flipped version of the image.

func FlipV

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

FlipV returns a vertically flipped version of the image.

func Resize

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

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

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

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

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.

Types

type ResampleFilter

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

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.

Jump to

Keyboard shortcuts

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