canvas

package module
v0.0.0-...-b4bf149 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2015 License: MIT Imports: 8 Imported by: 1

README

gosexy/canvas

This project is currently unmaintained and just kept for historical purposes, if you're looking for a better alternative take a look at imagick.

gosexy/canvas is an image processing library for Go that uses ImageMagick's MagickWand as backend.

Build Status

Requeriments

ImageMagick's MagickWand development files are required.

# OSX
$ brew install imagemagick

# Arch Linux
$ sudo pacman -S extra/imagemagick

# Debian
$ sudo aptitude install libmagickwand-dev

Installation

Just pull gosexy/canvas from github using go get:

$ go get github.com/gosexy/canvas

Usage

package main

import "github.com/gosexy/canvas"

func main() {
  img := canvas.New()
  defer img.Destroy()

  // Opening some image from disk.
  err := img.Open("examples/input/example.png")

  if err == nil {

    // Photo auto orientation based on EXIF tags.
    img.AutoOrientate()

    // Creating a squared thumbnail
    img.Thumbnail(100, 100)

    // Saving the thumbnail to disk.
    img.Write("examples/output/example-thumbnail.png")

  }
}

Documentation

See the online docs.

Authors

Documentation

Index

Constants

View Source
const (
	STROKE_BUTT_CAP   = uint(C.ButtCap)
	STROKE_ROUND_CAP  = uint(C.RoundCap)
	STROKE_SQUARE_CAP = uint(C.SquareCap)

	STROKE_MITER_JOIN = uint(C.MiterJoin)
	STROKE_ROUND_JOIN = uint(C.RoundJoin)
	STROKE_BEVEL_JOIN = uint(C.BevelJoin)

	FILL_EVEN_ODD_RULE = uint(C.EvenOddRule)
	FILL_NON_ZERO_RULE = uint(C.NonZeroRule)

	RAD_TO_DEG = 180 / math.Pi
	DEG_TO_RAD = math.Pi / 180

	UNDEFINED_ORIENTATION    = uint(C.UndefinedOrientation)
	TOP_LEFT_ORIENTATION     = uint(C.TopLeftOrientation)
	TOP_RIGHT_ORIENTATION    = uint(C.TopRightOrientation)
	BOTTOM_RIGHT_ORIENTATION = uint(C.BottomRightOrientation)
	BOTTOM_LEFT_ORIENTATION  = uint(C.BottomLeftOrientation)
	LEFT_TOP_ORIENTATION     = uint(C.LeftTopOrientation)
	RIGHT_TOP_ORIENTATION    = uint(C.RightTopOrientation)
	RIGHT_BOTTOM_ORIENTATION = uint(C.RightBottomOrientation)
	LEFT_BOTTOM_ORIENTATION  = uint(C.LeftBottomOrientation)

	POINT_FILTER          = uint(C.PointFilter)
	BOX_FILTER            = uint(C.BoxFilter)
	TRIANGLE_FILTER       = uint(C.TriangleFilter)
	HERMITE_FILTER        = uint(C.HermiteFilter)
	HANNING_FILTER        = uint(C.HanningFilter)
	HAMMING_FILTER        = uint(C.HammingFilter)
	BLACKMAN_FILTER       = uint(C.BlackmanFilter)
	GAUSSIAN_FILTER       = uint(C.GaussianFilter)
	QUADRATIC_FILTER      = uint(C.QuadraticFilter)
	CUBIC_FILTER          = uint(C.CubicFilter)
	CATROM_FILTER         = uint(C.CatromFilter)
	MITCHEL_FILTER        = uint(C.MitchellFilter)
	BESSEL_FILTER         = uint(C.BesselFilter)
	JINC_FILTER           = uint(C.BesselFilter)
	SINC_FAST_FILTER      = uint(C.SincFastFilter)
	SINC_FILTER           = uint(C.SincFilter)
	KAISER_FILTER         = uint(C.KaiserFilter)
	WELSH_FILTER          = uint(C.WelshFilter)
	PARZEN_FILTER         = uint(C.ParzenFilter)
	BOHMAN_FILTER         = uint(C.BohmanFilter)
	BARTLETT_FILTER       = uint(C.BartlettFilter)
	LAGRANGE_FILTER       = uint(C.LagrangeFilter)
	LANCZOS_FILTER        = uint(C.LanczosFilter)
	LANCZOS_SHARP_FILTER  = uint(C.LanczosSharpFilter)
	LANCZOS2_FILTER       = uint(C.Lanczos2Filter)
	LANCZOS2_SHARP_FILTER = uint(C.Lanczos2SharpFilter)
	ROBIDOUX_FILTER       = uint(C.RobidouxFilter)

	UNDEFINED_TYPE              = uint(C.UndefinedType)
	BILEVEL_TYPE                = uint(C.BilevelType)
	GRAYSCALE_TYPE              = uint(C.GrayscaleType)
	GRAYSCALE_MATTER_TYPE       = uint(C.GrayscaleMatteType)
	PALETTE_TYPE                = uint(C.PaletteType)
	PALETTE_MATTE_TYPE          = uint(C.PaletteMatteType)
	TRUE_COLOR_TYPE             = uint(C.TrueColorType)
	TRUE_COLOR_MATTE_TYPE       = uint(C.TrueColorMatteType)
	COLOR_SEPARATION_TYPE       = uint(C.ColorSeparationType)
	COLOR_SEPARATION_MATTE_TYPE = uint(C.ColorSeparationMatteType)
	OPTIMIZE_TYPE               = uint(C.OptimizeType)

	UNDEFINED_INTERLACE = uint(C.UndefinedInterlace)
	NO_INTERLACE        = uint(C.NoInterlace)
	LINE_INTERLACE      = uint(C.LineInterlace)
	PLANE_INTERLACE     = uint(C.PlaneInterlace)
	PARTITION_INTERLACE = uint(C.PartitionInterlace)
	GIF_INTERLACE       = uint(C.GIFInterlace)
	JPEG_INTERLACE      = uint(C.JPEGInterlace)
	PNG_INTERLACE       = uint(C.PNGInterlace)

	UNDEFINED_GRAVITY  = uint(C.UndefinedGravity)
	FORGET_GRAVITY     = uint(C.ForgetGravity)
	NORTH_WEST_GRAVITY = uint(C.NorthWestGravity)
	NORTH_GRAVITY      = uint(C.NorthGravity)
	NORTH_EAST_GRAVITY = uint(C.NorthEastGravity)
	WEST_GRAVITY       = uint(C.WestGravity)
	CENTER_GRAVITY     = uint(C.CenterGravity)
	EAST_GRAVITY       = uint(C.EastGravity)
	SOUTH_WEST_GRAVITY = uint(C.SouthWestGravity)
	SOUTH_GRAVITY      = uint(C.SouthGravity)
	SOUTH_EAST_GRAVITY = uint(C.SouthEastGravity)
)
View Source
const (
	UndefinedAlign Alignment = Alignment(C.UndefinedAlign)
	LeftAlign                = Alignment(C.LeftAlign)
	CenterAlign              = Alignment(C.CenterAlign)
	RightAlign               = Alignment(C.RightAlign)
)

Variables

This section is empty.

Functions

func Finalize

func Finalize()

Types

type Alignment

type Alignment uint

type Canvas

type Canvas struct {
	// contains filtered or unexported fields
}

Holds a Canvas object

func New

func New() *Canvas

Returns a new canvas object.

func (*Canvas) AdaptiveBlur

func (self *Canvas) AdaptiveBlur(sigma float64) error

Adaptively blurs the image by blurring less intensely near the edges and more intensely far from edges.

func (*Canvas) AdaptiveResize

func (self *Canvas) AdaptiveResize(width uint, height uint) error

Adaptively changes the size of the canvas, returns true on success.

func (*Canvas) AddNoise

func (self *Canvas) AddNoise() error

Adds random noise to the canvas.

func (*Canvas) Annotate

func (self *Canvas) Annotate(text string, x, y float64)

Draws a string at the specified coordinates and using the current canvas Alignment.

func (*Canvas) AnnotateWithProperties

func (self *Canvas) AnnotateWithProperties(text string, x, y float64, prop *TextProperties)

Draws a string at the specified coordinates and using the specified Text Properties Does not modify the canvas' default TextProperties

func (*Canvas) AppendCanvas

func (self *Canvas) AppendCanvas(source *Canvas, x int, y int) error

Puts a canvas on top of the current one.

func (*Canvas) AutoOrientate

func (self *Canvas) AutoOrientate() error

Auto-orientates canvas based on its original image's EXIF metadata

func (*Canvas) BackgroundColor

func (self *Canvas) BackgroundColor() string

Returns canvas' background color.

func (*Canvas) Blank

func (self *Canvas) Blank(width uint, height uint) error

Creates an empty canvas of the given dimensions.

func (*Canvas) Blob

func (self *Canvas) Blob() ([]byte, error)

func (*Canvas) Blur

func (self *Canvas) Blur(sigma float64) error

Convolves the canvas with a Gaussian function given its standard deviation.

func (*Canvas) Chop

func (self *Canvas) Chop(x int, y int, width uint, height uint) error

Removes a region of a canvas and collapses the canvas to occupy the removed portion.

func (*Canvas) Circle

func (self *Canvas) Circle(radius float64)

Draws a circle over the current drawing surface.

func (*Canvas) Clone

func (self *Canvas) Clone() *Canvas

Clones an image to another canvas

func (*Canvas) Contrast

func (self *Canvas) Contrast(sharpen bool) error

Enhances the intensity differences between the lighter and darker elements of the image. Set sharpen to a value other than 0 to increase the image contrast otherwise the contrast is reduced.

func (*Canvas) Crop

func (self *Canvas) Crop(x int, y int, width uint, height uint) error

Extracts a region from the canvas.

func (*Canvas) Destroy

func (self *Canvas) Destroy() error

Destroys canvas.

func (*Canvas) DrawAnnotation

func (self *Canvas) DrawAnnotation(content string, width, height uint) error

func (*Canvas) Ellipse

func (self *Canvas) Ellipse(a float64, b float64)

Draws an ellipse centered at the current coordinate system's origin.

func (*Canvas) Error

func (self *Canvas) Error() error

Returns the latest error reported by the MagickWand API.

func (*Canvas) FillColor

func (self *Canvas) FillColor() string

Returns the fill color for enclosed areas on the current drawing surface.

func (*Canvas) Fit

func (self *Canvas) Fit(width uint, height uint) error

Creates a thumbnail that fits within the given dimensions

func (*Canvas) Flip

func (self *Canvas) Flip() error

Creates a vertical mirror image by reflecting the pixels around the central x-axis.

func (*Canvas) Flop

func (self *Canvas) Flop() error

Creates a horizontal mirror image by reflecting the pixels around the central y-axis.

func (*Canvas) Font

func (self *Canvas) Font() (string, float64)

Returns canvas' current font name and size

func (*Canvas) FontFamily

func (self *Canvas) FontFamily() string

Returns canvas' current font family

func (*Canvas) FontName

func (self *Canvas) FontName() string

Returns canvas' current font name

func (*Canvas) FontSize

func (self *Canvas) FontSize() float64

Returns canvas' current font size

func (*Canvas) FontWeight

func (self *Canvas) FontWeight() uint

Returns canvas' current font weight

func (*Canvas) Format

func (self *Canvas) Format() string

func (*Canvas) GetFormat

func (self *Canvas) GetFormat() string

func (*Canvas) GetImageBlob

func (self *Canvas) GetImageBlob() ([]byte, error)

func (*Canvas) Height

func (self *Canvas) Height() uint

Returns canvas' height.

func (*Canvas) InterlaceScheme

func (self *Canvas) InterlaceScheme() uint

func (*Canvas) Line

func (self *Canvas) Line(x float64, y float64)

Draws a line starting on the current coordinate system origin and ending on the specified coordinates.

func (*Canvas) Metadata

func (self *Canvas) Metadata() map[string]string

Returns all metadata keys from the currently loaded image.

func (*Canvas) NewTextProperties

func (self *Canvas) NewTextProperties(readDefault bool) *TextProperties

Returns a TextProperties structure. Parameters:

  readDefault: if false, returns an empty structure.
				  if true, returns a structure set with current canvas settings

func (*Canvas) Open

func (self *Canvas) Open(filename string) error

Opens an image file, returns nil on success, error otherwise.

func (*Canvas) OpenBlob

func (self *Canvas) OpenBlob(blob []byte, length uint) error

Reads an image or image sequence from a blob.

func (*Canvas) PixelIterator

func (self *Canvas) PixelIterator(x, y int, width, height uint) *PixelIterator

func (*Canvas) PopDrawing

func (self *Canvas) PopDrawing() error

Destroys the current drawing surface and returns the latest surface that was pushed to the stack.

func (*Canvas) PushDrawing

func (self *Canvas) PushDrawing() error

Clones the current drawing surface and stores it in a stack.

func (*Canvas) Quality

func (self *Canvas) Quality() uint

Returns the compression quality of the canvas. Ranges from 1 (lowest) to 100 (highest).

func (*Canvas) QuantumRange

func (self *Canvas) QuantumRange() uint

func (*Canvas) Rectangle

func (self *Canvas) Rectangle(x float64, y float64)

Draws a rectangle over the current drawing surface.

func (*Canvas) Resize

func (self *Canvas) Resize(width uint, height uint) error

Changes the size of the canvas, returns true on success.

func (*Canvas) ResizeWithFilter

func (self *Canvas) ResizeWithFilter(width uint, height uint, filter uint, blur float32) error

Changes the size of the canvas using specified filter and blur, returns true on success.

func (*Canvas) Rotate

func (self *Canvas) Rotate(rad float64)

Applies a rotation of a given angle (in radians) on the current coordinate system.

func (*Canvas) RotateCanvas

func (self *Canvas) RotateCanvas(rad float64) error

Rotates the whole canvas.

func (*Canvas) Scale

func (self *Canvas) Scale(x float64, y float64)

Applies a scaling factor to the units of the current coordinate system.

func (*Canvas) SetBackgroundColor

func (self *Canvas) SetBackgroundColor(color string) error

Sets canvas' background color.

func (*Canvas) SetBrightness

func (self *Canvas) SetBrightness(factor float64) error

Adjusts the canvas's brightness given a factor (-1.0 thru 1.0)

func (*Canvas) SetCaption

func (self *Canvas) SetCaption(content string) error

func (*Canvas) SetColor

func (self *Canvas) SetColor(color string) bool

Sets canvas's foreground color.

func (*Canvas) SetContrast

func (self *Canvas) SetContrast(factor float64) error

func (*Canvas) SetFillColor

func (self *Canvas) SetFillColor(color string)

Sets the fill color for enclosed areas on the current drawing surface.

func (*Canvas) SetFont

func (self *Canvas) SetFont(font string, size float64)

Sets canvas' font name and size. If font is 0-length, the current font family is not changed If size is <= 0, the current font size is not changed

func (*Canvas) SetFontFamily

func (self *Canvas) SetFontFamily(family string)

Sets canvas' default font family

func (*Canvas) SetFontName

func (self *Canvas) SetFontName(font string)

Sets canvas' default font name

func (*Canvas) SetFontSize

func (self *Canvas) SetFontSize(size float64)

Sets canvas' default font size

func (*Canvas) SetFontWeight

func (self *Canvas) SetFontWeight(weight uint)

Sets canvas' default font weight

func (*Canvas) SetFormat

func (self *Canvas) SetFormat(format string) error

Sets the format of a particular image

func (*Canvas) SetGravity

func (self *Canvas) SetGravity(gravity uint)

func (*Canvas) SetHue

func (self *Canvas) SetHue(factor float64) error

Adjusts the canvas's hue given a factor (-1.0 thru 1.0)

func (*Canvas) SetInterlaceScheme

func (self *Canvas) SetInterlaceScheme(scheme uint) error

func (*Canvas) SetMetadata

func (self *Canvas) SetMetadata(key string, value string) error

Associates a metadata key with its value.

func (*Canvas) SetOption

func (self *Canvas) SetOption(key, value string) error

func (*Canvas) SetQuality

func (self *Canvas) SetQuality(quality uint) error

Changes the compression quality of the canvas. Ranges from 1 (lowest) to 100 (highest).

func (*Canvas) SetSaturation

func (self *Canvas) SetSaturation(factor float64) error

Adjusts the canvas's saturation given a factor (-1.0 thru 1.0)

func (*Canvas) SetSepiaTone

func (self *Canvas) SetSepiaTone(threshold float64) error

func (*Canvas) SetSize

func (self *Canvas) SetSize(width, height uint) error

func (*Canvas) SetStrokeAntialias

func (self *Canvas) SetStrokeAntialias(value bool)

Sets antialiasing setting for the current drawing stroke.

func (*Canvas) SetStrokeColor

func (self *Canvas) SetStrokeColor(color string)

Sets the stroke color on the current drawing surface.

func (*Canvas) SetStrokeLineCap

func (self *Canvas) SetStrokeLineCap(value uint)

Sets the type of the line cap on the current drawing surface.

func (*Canvas) SetStrokeLineJoin

func (self *Canvas) SetStrokeLineJoin(value uint)

Sets the type of the line join on the current drawing surface.

func (*Canvas) SetStrokeOpacity

func (self *Canvas) SetStrokeOpacity(value float64)

Sets the opacity of the stroke on the current drawing surface.

func (*Canvas) SetStrokeWidth

func (self *Canvas) SetStrokeWidth(value float64)

Sets the width of the stroke on the current drawing surface.

func (*Canvas) SetTextAlignment

func (self *Canvas) SetTextAlignment(a Alignment)

Sets canvas' default text alignment. Available values are: UndefinedAlign (?), LeftAlign, CenterAlign, RightAlign

func (*Canvas) SetTextAntialias

func (self *Canvas) SetTextAntialias(b bool)

Sets canvas' default text antialiasing option.

func (*Canvas) SetTextKerning

func (self *Canvas) SetTextKerning(k float64)

Sets canvas' default text antialiasing option.

func (*Canvas) SetTextProperties

func (self *Canvas) SetTextProperties(def *TextProperties)

Sets canvas' default TextProperties

func (*Canvas) SetType

func (self *Canvas) SetType(imageType uint) error

func (*Canvas) SharpenImage

func (self *Canvas) SharpenImage(radius float32, sigma float32, channel int) error

Sharpens an image. We convolve the image with a Gaussian operator of the given radius and standard deviation (sigma). For reasonable results, the radius should be larger than sigma. Use a radius of 0 and selects a suitable radius for you. You can pass 0 as channel number - to use default channels

func (*Canvas) SigmoidalContrast

func (self *Canvas) SigmoidalContrast(sharpen bool, alpha float64, beta float64) error

Adjusts the contrast of an image with a non-linear sigmoidal contrast algorithm. Increase the contrast of the image using a sigmoidal transfer function without saturating highlights or shadows. Contrast indicates how much to increase the contrast (0 is none; 3 is typical; 20 is pushing it); mid-point indicates where midtones fall in the resultant image (0 is white; 50 is middle-gray; 100 is black). Set sharpen to true to increase the image contrast otherwise the contrast is reduced.

func (*Canvas) Strip

func (self *Canvas) Strip() error

func (*Canvas) StrokeAntialias

func (self *Canvas) StrokeAntialias() bool

Returns antialiasing setting for the current drawing stroke.

func (*Canvas) StrokeColor

func (self *Canvas) StrokeColor() string

Returns the stroke color on the current drawing surface.

func (*Canvas) StrokeLineCap

func (self *Canvas) StrokeLineCap() uint

Returns the type of the line cap on the current drawing surface.

func (*Canvas) StrokeLineJoin

func (self *Canvas) StrokeLineJoin() uint

Returns the type of the line join on the current drawing surface.

func (*Canvas) StrokeOpacity

func (self *Canvas) StrokeOpacity() float64

Returns the opacity of the stroke on the current drawing surface.

func (*Canvas) StrokeWidth

func (self *Canvas) StrokeWidth() float64

Returns the width of the stroke on the current drawing surface.

func (*Canvas) TextAlignment

func (self *Canvas) TextAlignment() Alignment

Returns the canvas' current text aligment

func (*Canvas) TextAntialias

func (self *Canvas) TextAntialias() bool

Returns the canvas' current text aligment

func (*Canvas) TextKerning

func (self *Canvas) TextKerning() float64

Returns the canvas' current text aligment

func (*Canvas) TextProperties

func (self *Canvas) TextProperties() *TextProperties

Gets a copy of canvas' current TextProperties

func (*Canvas) Thumbnail

func (self *Canvas) Thumbnail(width uint, height uint) error

Converts the current image into a thumbnail of the specified width and height preserving ratio. It uses Crop() to clip the image to the specified area.

If width or height are bigger than the current image, a centered thumbnail will be produced.

Is width and height are smaller than the current image, the image will be resized and cropped, if needed.

func (*Canvas) Translate

func (self *Canvas) Translate(x float64, y float64)

Moves the current coordinate system origin to the specified coordinate.

func (*Canvas) Type

func (self *Canvas) Type() uint

func (*Canvas) Update

func (self *Canvas) Update() error

Copies a drawing surface to the canvas.

func (*Canvas) Width

func (self *Canvas) Width() uint

Returns canvas' width.

func (*Canvas) Write

func (self *Canvas) Write(filename string) error

Writes canvas to a file, returns true on success.

type Pixel

type Pixel struct {
	// contains filtered or unexported fields
}

func (*Pixel) Blue

func (self *Pixel) Blue() float64

func (*Pixel) Destroy

func (self *Pixel) Destroy()

func (*Pixel) Green

func (self *Pixel) Green() float64

func (*Pixel) Red

func (self *Pixel) Red() float64

func (*Pixel) SetColor

func (self *Pixel) SetColor(color string) error

type PixelIterator

type PixelIterator struct {
	// contains filtered or unexported fields
}

func (*PixelIterator) Destroy

func (self *PixelIterator) Destroy()

func (*PixelIterator) Error

func (self *PixelIterator) Error() error

func (*PixelIterator) NextRow

func (self *PixelIterator) NextRow() (row []*Pixel)

func (*PixelIterator) Sync

func (self *PixelIterator) Sync() error

type TextProperties

type TextProperties struct {
	Font   string
	Family string
	Size   float64
	// Stretch		C.StretchType
	Weight uint
	// Style		C.StyleType
	// Resolution  [2]C.double
	Alignment Alignment
	Antialias bool
	// Decoration	C.DecorationType
	// Encoding	string
	Kerning float64
	// Interline	float64
	// Interword	float64
	UnderColor *C.PixelWand
}

structure containing all text properties for an annotation except the colors that are defined by FillColor and StrokeColor

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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