magick

package module
v0.0.0-...-82956e7 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: MIT Imports: 17 Imported by: 0

README

magick image library for Go (golang)

GoDoc

ImageMagick bindings for Go (golang)

Requires Go 1.2 (or a 1.2 release candidate) due to C function pointer support.

Supports both ImageMagick and GraphicsMagick. The former is used by default, while the latter can be enabled by building the package with the gm build tag.

Installation requires either ImageMagick or GraphicsMagick and libgif, with their respective development packages.

Then, install this package by running.

    go get github.com/rainycape/magick

Some functions are not documented. For those, see the MagickCore documentation at http://www.imagemagick.org/script/magick-core.php.

Documentation

Index

Constants

View Source
const (
	CharPixel    Storage = C.CharPixel
	ShortPixel           = C.ShortPixel
	IntegerPixel         = C.IntegerPixel
	LongPixel            = C.LongPixel
	FloatPixel           = C.FloatPixel
	DoublePixel          = C.DoublePixel
)

Variables

View Source
var (
	ErrNoSuchFrame = errors.New("no such frame")
	ErrNoData      = errors.New("no image data")
)

Functions

func Backend

func Backend() string

Backend returns the name of the library backend which was selected at build time. It must be either "ImageMagick" or "GraphicsMagick".

func QuantumDepth

func QuantumDepth() uint

QuantumDepth returns the color depth used in magick. This value is selected when compiling ImageMagick or GraphicsMagick and it's usually 8.

func QuantumRange

func QuantumRange() uint64

QuantumRange returns the maximum value representable by the current QuantumDepth (= pow(2, QuantumDepth) - 1).

func SupportedFormats

func SupportedFormats() ([]string, error)

Supported formats returns a list with the names of all supported image formats. This varies depending on the backend and the compile options that have been used while building IM or GM.

Types

type AffineMatrix

type AffineMatrix struct {
	Sx, Sy, Rx, Ry, Tx, Ty float64
}

type Channel

type Channel C.ChannelType
const (
	CRed     Channel = C.RedChannel     /* RGB Red channel */
	CCyan    Channel = C.CyanChannel    /* CMYK Cyan channel */
	CGreen   Channel = C.GreenChannel   /* RGB Green channel */
	CMagenta Channel = C.MagentaChannel /* CMYK Magenta channel */
	CBlue    Channel = C.BlueChannel    /* RGB Blue channel */
	CYellow  Channel = C.YellowChannel  /* CMYK Yellow channel */
	COpacity Channel = C.OpacityChannel /* Opacity channel */
	CBlack   Channel = C.BlackChannel   /* CMYK Black (K) channel */
	CAll     Channel = C.AllChannels    /* Color channels */
	CGray    Channel = C.GrayChannel    /* Color channels represent an intensity. */
)

type ChannelStatistics

type ChannelStatistics struct {
	Minimum  float64
	Maximum  float64
	Mean     float64
	StdDev   float64
	Variance float64
	// The following fields are only filled in when building
	// against ImageMagick
	Kurtosis float64
	Skewness float64
}

ChannelStatistics includes several statistics about a color channel. Magick normalizes all fields in this structure to the interval [0, 1].

type Colorspace

type Colorspace C.ColorspaceType

When encoding an output image, the colorspaces RGB, CMYK, and GRAY may be specified. The CMYK option is only applicable when writing TIFF, JPEG, and Adobe Photoshop bitmap (PSD) files.

const (
	RGB           Colorspace = C.RGBColorspace         // Red, Green, Blue colorspace.
	GRAY          Colorspace = C.GRAYColorspace        // Similar to Luma (Y) according to ITU-R 601
	TRANSPARENT   Colorspace = C.TransparentColorspace // RGB which preserves the matte while quantizing colors.
	OHTA          Colorspace = C.OHTAColorspace
	XYZ           Colorspace = C.XYZColorspace // CIE XYZ
	YCC           Colorspace = C.YCCColorspace // Kodak PhotoCD PhotoYCC
	YIQ           Colorspace = C.YIQColorspace
	YPBPR         Colorspace = C.YPbPrColorspace
	YUV           Colorspace = C.YUVColorspace         // YUV colorspace as used for computer video.
	CMYK          Colorspace = C.CMYKColorspace        // Cyan, Magenta, Yellow, Black colorspace.
	SRGB          Colorspace = C.sRGBColorspace        // Kodak PhotoCD sRGB
	HSL           Colorspace = C.HSLColorspace         // Hue, saturation, luminosity
	HWB           Colorspace = C.HWBColorspace         // Hue, whiteness, blackness
	LAB           Colorspace = C.LABColorspace         // ITU LAB
	REC_601_LUMA  Colorspace = C.Rec601LumaColorspace  // Luma (Y) according to ITU-R 601
	REC_601_YCBCR Colorspace = C.Rec601YCbCrColorspace // YCbCr according to ITU-R 601
	REC_709_LUMA  Colorspace = C.Rec709LumaColorspace  // Luma (Y) according to ITU-R 709
	REC_709_YCBCR Colorspace = C.Rec709YCbCrColorspace // YCbCr according to ITU-R 709
)

func (Colorspace) String

func (c Colorspace) String() string

type Composite

type Composite int

Composite represents a composition operation. Refer to the individual constants for more information. Note that not all compositions are supported by the GraphicsMagick backend.

const (
	CompositeAlpha Composite = iota + 1
	CompositeAtop
	CompositeBlend
	CompositeBlur
	CompositeBumpmap
	CompositeChangeMask
	CompositeClear
	CompositeColorBurn
	CompositeColorDodge
	CompositeColorize
	CompositeCopyBlack
	CompositeCopyBlue
	CompositeCopy
	CompositeCopyCyan
	CompositeCopyGreen
	CompositeCopyMagenta
	CompositeCopyAlpha
	CompositeCopyRed
	CompositeCopyYellow
	CompositeDarken
	CompositeDarkenIntensity
	CompositeDifference
	CompositeDisplace
	CompositeDissolve
	CompositeDistort
	CompositeDivideDst
	CompositeDivideSrc
	CompositeDstAtop
	CompositeDst
	CompositeDstIn
	CompositeDstOut
	CompositeDstOver
	CompositeExclusion
	CompositeHardLight
	CompositeHue
	CompositeIn
	CompositeIntensity
	CompositeLighten
	CompositeLightenIntensity
	CompositeLinearBurn
	CompositeLinearDodge
	CompositeLinearLight
	CompositeLuminize
	CompositeMathematics
	CompositeMinusDst
	CompositeMinusSrc
	CompositeModulate
	CompositeModulusAdd
	CompositeModulusSubtract
	CompositeMultiply
	CompositeNo
	CompositeOut
	CompositeOver
	CompositeOverlay
	CompositePegtopLight
	CompositePinLight
	CompositePlus
	CompositeReplace
	CompositeSaturate
	CompositeScreen
	CompositeSoftLight
	CompositeSrcAtop
	CompositeSrc
	CompositeSrcIn
	CompositeSrcOut
	CompositeSrcOver
	CompositeThreshold
	CompositeUndefined
	CompositeVividLight
	CompositeXor
)

func (Composite) String

func (c Composite) String() string

type CropStrategy

type CropStrategy int

CropStrategy defines the strategy used to crop an image to a given ratio.

const (
	// When cropping to a given aspect ratio, discard content
	// from the edges of the image and keep the content at the center.
	CSCenter CropStrategy = iota
	// When cropping to a given aspect ratio, grab the section of the
	// image with higher entropy. This is useful when you want to crop
	// the image to a given ratio and end up with the most 'meaningful'
	// part of the image.
	CSMaxEntropy
)

type ErrorStats

type ErrorStats struct {
	MeanPerPixel      float64
	NormalizedMean    float64
	NormalizedMaximum float64
}

ErrorStats represents the difference between two compared images.

func (*ErrorStats) IsZero

func (stats *ErrorStats) IsZero() bool

IsZero returns true iff the two compared images are equal.

type Filter

type Filter C.FilterTypes
const (
	FPoint     Filter = C.PointFilter
	FBox       Filter = C.BoxFilter
	FTriangle  Filter = C.TriangleFilter
	FHermite   Filter = C.HermiteFilter
	FHanning   Filter = C.HanningFilter
	FHamming   Filter = C.HammingFilter
	FBlackman  Filter = C.BlackmanFilter
	FGaussian  Filter = C.GaussianFilter
	FQuadratic Filter = C.QuadraticFilter
	FCubic     Filter = C.CubicFilter
	FCatrom    Filter = C.CatromFilter
	FMitchell  Filter = C.MitchellFilter
	FLanczos   Filter = C.LanczosFilter
	FBessel    Filter = C.BesselFilter
	FSinc      Filter = C.SincFilter
)

func (Filter) String

func (f Filter) String() string

type FloatMatrix

type FloatMatrix [][]float64

func NewDCTMatrix

func NewDCTMatrix(order int) FloatMatrix

func NewFloatMatrix

func NewFloatMatrix(rows int, columns int) FloatMatrix

func (FloatMatrix) Columns

func (m FloatMatrix) Columns() int

func (FloatMatrix) Multiply

func (m FloatMatrix) Multiply(n FloatMatrix) (FloatMatrix, error)

func (FloatMatrix) Rows

func (m FloatMatrix) Rows() int

func (FloatMatrix) SubMatrix

func (m FloatMatrix) SubMatrix(x int, y int, rows int, columns int) (FloatMatrix, error)

func (FloatMatrix) Transposed

func (m FloatMatrix) Transposed() FloatMatrix

func (FloatMatrix) UnrollX

func (m FloatMatrix) UnrollX() []float64

UnrollX returns all values in a slice which contains all rows in increasing order.

func (FloatMatrix) UnrollY

func (m FloatMatrix) UnrollY() []float64

UnrollX returns all values in a slice which contains all columns in increasing order.

type Frame

type Frame struct {
	X          int
	Y          int
	Width      uint
	Height     uint
	InnerBevel int
	OuterBevel int
}

type Histogram

type Histogram struct {
	Items []*HistogramItem
}

type HistogramItem

type HistogramItem struct {
	Color *Pixel
	Count int
}

type Image

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

Image represents an in-memory decoded image. Some images (like e.g. GIF animations) might have multiple frames. Unless indicated otherwise, functions work in the same way with both single a multi-frame images, performing coalescing when needed. To operate on a single frame use e.g. im.Frame(i).Resize() instead of im.Resize(). Frames might be added or removed with list related functions, like Append() or Remove().

func Constitute

func Constitute(width int, height int, channels string, st Storage, pixels []byte) (*Image, error)

Constitute returns a new image from in-memory data. channels must be a string formed or the following characters, each one representing a channel, in order.

R = red
G = green
B = blue
A = alpha (same as Transparency)
O = Opacity
T = Transparency
C = cyan
Y = yellow
M = magenta
K = black
I = intensity (for grayscale)
P = pad, to skip over a chnnel which is intentionally ignored

Creation of an alpha channel for CMYK images is currently not supported. Note that pixels must be either empty, resulting in an image with all pixels the zero values, or have the appropiate size for the image dimensions, the number of channels and the storage type.

func Decode

func Decode(r io.Reader) (*Image, error)

Decode tries to decode an image from the given io.Reader. If the image can't be decoded or it's corrupt, an error will be returned. Depending on the backend and compile time options, the number of supported formats might vary. Use SupportedFormats() to list the all.

func DecodeData

func DecodeData(data []byte) (*Image, error)

DecodeData works like Decode, but accepts a []byte rather than an io.Reader.

func DecodeFile

func DecodeFile(filename string) (*Image, error)

DecodeFile works like Decode, but accepts a filename.

func New

func New(width int, height int) (*Image, error)

New returns a new RGBA image with the given size. If you need more granularity, see Constitute.

func (*Image) AddBorder

func (im *Image) AddBorder(r Rect, c *Pixel) (*Image, error)

func (*Image) AddFrame

func (im *Image) AddFrame(f Frame, c *Pixel) (*Image, error)

func (*Image) AffineTransform

func (im *Image) AffineTransform(m *AffineMatrix) (*Image, error)

AffineTransform returns a new image created by transforming the original image as dictated by the affine matrix.

func (*Image) Append

func (im *Image) Append(image *Image) error

func (*Image) Apply

func (im *Image) Apply(f func(*Image) (*Image, error)) (*Image, error)

func (*Image) ApplyDataFunc

func (im *Image) ApplyDataFunc(f C.ImageDataFunc, data interface{}) (*Image, error)

ApplyDataFunc calls the given C.ImageDataFunc with the data argument (which must be a pointer) for all the frames in the given image and returns the results. The given function only needs to work on individual images. ApplyDataFunc will coalesce the original image and create a new sequence of images if required.

func (*Image) ApplyFunc

func (im *Image) ApplyFunc(f C.ImageFunc) (*Image, error)

ApplyFunc calls the given C.ImageFunc for all the frames in the given image and returns the results. The given function only needs to work on individual images. ApplyFunc will coalesce the original image and create a new sequence of images if required.

func (*Image) ApplyRectFunc

func (im *Image) ApplyRectFunc(f C.ImageDataFunc, r Rect) (*Image, error)

ApplyRectFunc calls the given C.ImageDataFunc with Rect argument converted to a *C.RectangleInfo for all the frames in the given image and returns the results. The given function only needs to work on individual images. ApplyRectFunc will coalesce the original image and create a new sequence of images if required.

func (*Image) AverageColor

func (im *Image) AverageColor() (*Pixel, error)

AverageColor returns the image's average color as a *Pixel.

func (*Image) BackgroundColor

func (im *Image) BackgroundColor() *Pixel

BackgroundColor returns the image background color.

func (*Image) BorderColor

func (im *Image) BorderColor() *Pixel

BorderColore returns the image border color.

func (*Image) ChannelDepth

func (im *Image) ChannelDepth(ch Channel) (uint, error)

ChannelDepth returns the depth of the given channel.

func (*Image) ChannelImage

func (im *Image) ChannelImage(ch Channel) (*Image, error)

ChannelImage returns a new image with all the channels equal to the given channel. e.g. on an image with all pixels with red = 255, im.ChannelImage(magick.CRed) will result in a white image, since green and blue will be set to the red value. See also ToChannelImage.

func (*Image) Chop

func (im *Image) Chop(r Rect) (*Image, error)

func (*Image) Clone

func (im *Image) Clone() (*Image, error)

Clone returns a copy of the image. If the image has multiple frames, it copies all of them. To Clone just one frame use im.Frame(i).Clone().

func (*Image) Coalesce

func (im *Image) Coalesce() (*Image, error)

Coalesce composites a set of images while respecting any page offsets and disposal methods. GIF, MIFF, and MNG animation sequences typically start with an image background and each subsequent image varies in size and offset. Coalesce() returns a new sequence where each image in the sequence is the same size as the first and composited with the next image in the sequence.

func (*Image) Colorspace

func (im *Image) Colorspace() Colorspace

Colorspace returns the image colorspace.

func (*Image) Compare

func (im *Image) Compare(src *Image) (*ErrorStats, error)

Compare returns comparison of two images as an ErrorStatus. See also IsEqual.

func (*Image) Composite

func (im *Image) Composite(c Composite, draw *Image, x int, y int) error

Composite modifies the image, drawing the draw Image argument at offset (x, y) using the c Composite operation.

func (*Image) CompositeInto

func (im *Image) CompositeInto(c Composite, canvas *Image, x int, y int) error

CompositeInto is equivalent to canvas.Composite/c, im, x, y). See Image.Composite for more information.

func (*Image) Convolve

func (im *Image) Convolve(order int, kernel []float64) (*Image, error)

Convolve applies the given convolution kernel to the image. The order parameter must be a non-negative odd number, while the kernel parameter must have either order*order elements or just one element (in the latter case, it's interpreted as having all elements set to that first value).

func (*Image) Crop

func (im *Image) Crop(r Rect) (*Image, error)

func (*Image) CropResize

func (im *Image) CropResize(width, height int, filter Filter, cs CropStrategy) (*Image, error)

func (*Image) CropToRatio

func (im *Image) CropToRatio(ratio float64, cs CropStrategy) (*Image, error)

func (*Image) Deconstruct

func (im *Image) Deconstruct() (*Image, error)

func (*Image) Delay

func (im *Image) Delay() int

Delay returns the time this image stays visible in an animation, in 1/100ths of a second. If this image is not part of a sequence of animated images, it returns 0.

func (*Image) Depth

func (im *Image) Depth() int

Depth returns the pixel depth of the image, usually 8.

func (*Image) DestroyProperties

func (im *Image) DestroyProperties()

DestroyPropertys removes all properties from the image.

func (*Image) Dispose

func (im *Image) Dispose()

Dispose frees the memory associated with the image. If you try to use a disposed image, you'll get undefined behavior. Note that you don't usually need to call Dispose manually. Just before an Image is collected by the GC, its Dispose method will be called for you. However, if you're allocating multiple images in a loop, it's probably better to manually Dispose them as soon as you don't need them anymore, to avoid the temporary memory usage from getting too high. Behind the scenes, Image uses a finalizer to call Dispose. Please, see http://golang.org/pkg/runtime/#SetFinalizer for more information about finalizers.

func (*Image) Duration

func (im *Image) Duration() int

func (*Image) Encode

func (im *Image) Encode(w io.Writer, info *Info) error

Encode writes the image to the given io.Writer, encoding it according to the info parameter. Please, see the Info type for the available encoding options.

func (*Image) Entropy

func (im *Image) Entropy() float32

func (*Image) EntropyRect

func (im *Image) EntropyRect(r Rect) float32

func (*Image) Extent

func (im *Image) Extent(r Rect) (*Image, error)

func (*Image) First

func (im *Image) First() *Image

func (*Image) Flatten

func (im *Image) Flatten() (*Image, error)

Flatten merges a sequence of images. This is useful for combining Photoshop layers into a single image.

func (*Image) Flip

func (im *Image) Flip() (*Image, error)

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

func (*Image) FloatMatrix

func (im *Image) FloatMatrix() (FloatMatrix, error)

FloatMatrix returns an Image in the GRAY colorspace as FloatMatrix, where each pixel represents an element of the matrix. Each element is normalized to the [0,1] range.

func (*Image) Flop

func (im *Image) Flop() (*Image, error)

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

func (*Image) Format

func (im *Image) Format() string

Format returns the format used to decode this image.

func (*Image) Frame

func (im *Image) Frame(idx int) (*Image, error)

func (*Image) FrameIndex

func (im *Image) FrameIndex() int

func (*Image) Func

func (im *Image) Func(f C.ImageFunc) (*Image, error)

Func calls the given C.ImageFunc, which expects a sequence of images rather than a single frame and results the result as a new Image.

func (*Image) GifEncode

func (im *Image) GifEncode() ([]byte, error)

GifEncode encodes the Image as GIF using giflib rather than ImageMagick or GraphicksMagick. While this will result in a lower quality GIF, encoding is 9-10x faster and produces files ~20% smaller.

func (*Image) GoImage

func (im *Image) GoImage() (image.Image, error)

GoImage returns the image converted to an RGBA image.Image. Note that since the in-memory representation is different, the conversion could introduce small errors due to rounding in semitransparent pixels, because Go uses premultiplied alpha while GM/IM does not.

func (*Image) HasProperty

func (im *Image) HasProperty(key string) bool

HasProperty returns wheter the image has a property with the given key, even if it's set to an empty string.

func (*Image) Height

func (im *Image) Height() int

Height returns the image height in pixels.

func (*Image) Histogram

func (im *Image) Histogram() (*Histogram, error)

func (*Image) Image

func (im *Image) Image() *C.Image

Image returns the underlying *C.Image. This is useful for calling GM or IM directly and performing operations which are not yet supported by magick.

func (*Image) ImportChannel

func (im *Image) ImportChannel(src *Image, ch Channel) error

ImportChannel imports the given channel from the src image.

func (*Image) IsEqual

func (im *Image) IsEqual(src *Image) (bool, error)

IsEqual returns wheter two images are equal. See also Compare.

func (*Image) IsOrphan

func (im *Image) IsOrphan() bool

func (*Image) IsPalette

func (im *Image) IsPalette() (bool, error)

func (*Image) Last

func (im *Image) Last() *Image

func (*Image) Magnify

func (im *Image) Magnify() (*Image, error)

Magnify is a convenience method that scales an image proportionally to twice its size.

func (*Image) MatteColor

func (im *Image) MatteColor() *Pixel

MatteColor returns the image matter color.

func (*Image) Minify

func (im *Image) Minify() (*Image, error)

Minify is a convenience method that scales an image proportionally to half its size.

func (*Image) Mosaic

func (im *Image) Mosaic() (*Image, error)

func (*Image) NColors

func (im *Image) NColors() (int, error)

func (*Image) NFrames

func (im *Image) NFrames() int

func (*Image) Next

func (im *Image) Next() *Image

func (*Image) Operate

func (im *Image) Operate(op Operator, value float64) error

Operate is a shorthand for OperateChannel(op, CAll, value).

func (*Image) OperateChannel

func (im *Image) OperateChannel(op Operator, ch Channel, value float64) error

Operate applies the selected operator to the selected channel(s) of the image. The image is modified and only errors are returned. This method works only on single images, so if you're working with animations you must perform the coalescing and then apply the operator to each frame. See the Operator type for the available operations.

func (*Image) PHash

func (im *Image) PHash() (PHash, error)

PHash returns a perceptual hash of the image. The algorithm is based on the pHash library and works as follows:

1 - Transform the image to grayscale.
2 - Apply convolution using a (7, []float64{1}) kernel.
3 - Scale to 32x32.
4 - Compute the DCT for the image.
5 - Grab the 8x8 submatrix starting at (1, 1).
6 - Unroll the matrix by the x axis into an array.
7 - Compute the median for the previous array.
8 - Generate a 64bit hash, where bit x = 1 iff array[x] > median.

Note that due to differences in scaling and convolution algorithms, this function will generate different values for the same image depending on the backend library (IM or GM).

func (*Image) Pixel

func (im *Image) Pixel(x int, y int) (*Pixel, error)

Pixel returns a pixel from the image at the given (x, y). coordinates. Note that modifications to the returned Pixel won't alter the image. Use SetPixel to change a pixel in the image.

func (*Image) Pixels

func (im *Image) Pixels(r Rect) ([]*Pixel, error)

Pixels returns the image pixels contained in the given rect, in row major order. Note that modifications to the returned pixels won't alter the image. Use SetPixels to change pixels in the image.

func (*Image) Prepend

func (im *Image) Prepend(image *Image) error

func (*Image) Prev

func (im *Image) Prev() *Image

func (*Image) Properties

func (im *Image) Properties() []string

Properties returns the keys of the properties that the image contains.

func (*Image) Property

func (im *Image) Property(key string) string

Property returns the property value assocciated with the given key. Note that both non-present keys and keys set to "" will return an empty string. To check if an image has a property defined use Image.HasProperty.

func (*Image) Raise

func (im *Image) Raise(r Rect, threedimensional bool) (*Image, error)

func (*Image) Rect

func (im *Image) Rect() Rect

Rect is a conveniency function which returns a Rect at (0, 0) with the image dimensions.

func (*Image) Remove

func (im *Image) Remove() bool

func (*Image) RemoveFirst

func (im *Image) RemoveFirst() bool

func (*Image) RemoveIndex

func (im *Image) RemoveIndex(idx int) bool

func (*Image) RemoveLast

func (im *Image) RemoveLast() bool

func (*Image) RemoveProperty

func (im *Image) RemoveProperty(key string) bool

RemoveProperty removes the property specified by key.

func (*Image) Resize

func (im *Image) Resize(width, height int, filter Filter) (*Image, error)

Resize works like ResizeBlur, but sets the blur to 1

func (*Image) ResizeBlur

func (im *Image) ResizeBlur(width, height int, filter Filter, blur float64) (*Image, error)

ResizeBlur returns a new image resized to the given dimensions using the provided filter and blur factor (where > 1 is blurry, < 1 is sharp). If width or height is < 0, it's calculated proportionally to the other dimension. If both of them are < 0, an error is returned.

func (*Image) Reverse

func (im *Image) Reverse()

func (*Image) Roll

func (im *Image) Roll(xoffset, yoffset int) (*Image, error)

func (*Image) Sample

func (im *Image) Sample(width, height int) (*Image, error)

Sample scales an image to the desired dimensions with pixel sampling. Unlike other scaling methods, this method does not introduce any additional color into the scaled image.

func (*Image) Scale

func (im *Image) Scale(width, height int) (*Image, error)

Scale changes the size of an image to the given dimensions.

func (*Image) SetBackgroundColor

func (im *Image) SetBackgroundColor(px *Pixel)

SetBackgroundColor changes the image background color.

func (*Image) SetBorderColor

func (im *Image) SetBorderColor(px *Pixel)

SetBorderColor changes the image border color.

func (*Image) SetChannelDepth

func (im *Image) SetChannelDepth(ch Channel, depth uint) error

SetChannelDepth sets the depth of the channel. The range of depth is 1 to QuantumDepth.

func (*Image) SetColorspace

func (im *Image) SetColorspace(cs Colorspace)

SetColorspace changes the image colorspace. Note that this only changes how the pixels are interpreted. If you want to transform the image to another colorspace use TransformColorspace().

func (*Image) SetMatteColor

func (im *Image) SetMatteColor(px *Pixel)

SetMatteColor changes the image matte color.

func (*Image) SetPixel

func (im *Image) SetPixel(x int, y int, p *Pixel) error

SetPixel changes the pixel at the given (x, y) coordinates.

func (*Image) SetPixels

func (im *Image) SetPixels(r Rect, p []*Pixel) error

SetPixels changes the pixels in the given rect, in row major order. Note that the number of elements in p must match r.Width * r.Height, otherwise an error is returned.

func (*Image) SetProperty

func (im *Image) SetProperty(key string, value string) bool

SetProperty adds a new property to the image. If the property already exists, it's overwritten. Returns true if the property could be added to the list, false otherwise. For removing a property, see Image.RemoveProperty.

func (*Image) Shave

func (im *Image) Shave(r Rect) (*Image, error)

func (*Image) Signature

func (im *Image) Signature() string

Signature computes a message digest from an image pixel stream with an implementation of the NIST SHA-256 Message Digest algorithm. This signature uniquely identifies the image and is convenient for determining if an image has been modified or whether two images are identical.

func (*Image) Statistics

func (im *Image) Statistics() (*Statistics, error)

func (*Image) Thumbnail

func (im *Image) Thumbnail(width, height int) (*Image, error)

Thumbnail changes the size of an image to the given dimensions. This method was designed by Bob Friesenhahn as a low cost thumbnail generator.

func (*Image) ToChannelImage

func (im *Image) ToChannelImage(ch Channel) error

ToChannelImage works like ChannelImage, but modifies the image in place.

func (*Image) ToColorspace

func (im *Image) ToColorspace(cs Colorspace) error

ToColorspace changes the image colorspace in place.

func (*Image) Transform

func (im *Image) Transform(crop, image string) *Image

func (*Image) TransformColorspace

func (im *Image) TransformColorspace(cs Colorspace) (*Image, error)

TransformColorspace returns a new image by covnerting the original to the given colorspace while also changing the pixels to represent the same image in the new colorspace.

func (*Image) Width

func (im *Image) Width() int

Width returns the image width in pixels.

type Info

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

Info is used to specify the encoding parameters like format and quality when encoding and image.

func NewInfo

func NewInfo() *Info

NewInfo returns a newly allocated *Info structure. Do not create Info objects directly, since they need to allocate some internal structures while being created.

func (*Info) Colorspace

func (in *Info) Colorspace() Colorspace

Colorspace returns the colorspace used when encoding the image.

func (*Info) Format

func (in *Info) Format() string

Format returns the format used for encoding the image.

func (*Info) Quality

func (in *Info) Quality() uint

Quality returns the quality used when compressing the image. This parameter does not affect all formats.

func (*Info) SetColorspace

func (in *Info) SetColorspace(cs Colorspace)

SetColorspace set the colorspace used when encoding the image. Note that not all colorspaces are supported for encoding. See the documentation on Colorspace.

func (*Info) SetFormat

func (in *Info) SetFormat(format string)

SetFormat sets the image format for encoding this image. See http://www.graphicsmagick.org for a list of supported formats.

func (*Info) SetQuality

func (in *Info) SetQuality(q uint)

SetQuality sets the quality used when compressing the image. This parameter does not affect all formats.

type Operator

type Operator int

Operator represents an operation to be applied on all the pixels of the selected channel(s) of an image.

const (
	OpAdd                 Operator = iota + 1 /* Add value */
	OpAnd                                     /* Bitwise AND value */
	OpAssign                                  /* Direct value assignment */
	OpDepth                                   /* Divide by value */
	OpDivide                                  /* Bitwise left-shift value N bits */
	OpGamma                                   /* Adjust image gamma */
	OpLog                                     /* log(quantum*value+1)/log(value+1) */
	OpLShift                                  /* Bitwise left-shift value N bits */
	OpMax                                     /* Assign value if > quantum */
	OpMin                                     /* Assign value if < quantum */
	OpMultiply                                /* Multiply by value */
	OpNegate                                  /* Negate channel, ignore value */
	OpGaussianNoise                           /* Gaussian noise */
	OpImpulseNoise                            /* Impulse noise */
	OpLaplacianNoise                          /* Laplacian noise */
	OpMultiplicativeNoise                     /* Multiplicative gaussian noise */
	OpPoissonNoise                            /* Poisson noise */
	OpRandomNoise                             /* Random noise */
	OpUniformNoise                            /* Uniform noise */
	OpOr                                      /* Bitwise OR value */
	OpPow                                     /* Power function: pow(quantum,value) */
	OpRShift                                  /* Bitwise right shift value */
	OpSubstract                               /* Subtract value */
	OpThresholdBlack                          /* Below threshold is black */
	OpThreshold                               /* Above threshold white, otherwise black */
	OpThresholdWhite                          /* Above threshold is white */
	OpXor                                     /* Bitwise XOR value */
)

func (Operator) String

func (o Operator) String() string

type Optimizer

type Optimizer func([]byte) ([]byte, error)

type PHash

type PHash uint64

PHash represents a perceptual hash. Use Image.PHash() to obtain the perceptual hash of an image.

func (PHash) Compare

func (p PHash) Compare(q PHash) float64

Compare returns a number between in the [0,1] interval. The difference is calculated as number of different bits / 64. This means 0 indicates that the hashes are equal, while 1 indicates that the hashes have no bits in common.

func (PHash) String

func (p PHash) String() string

func (PHash) Uint64

func (p PHash) Uint64() uint64

type Pixel

type Pixel struct {
	Red     uint8
	Green   uint8
	Blue    uint8
	Opacity uint8 // 0 means fully opaque, 255 means fully transparent
}

Pixel represents a color identified by its red, green, blue and alpha components. Their value goes from 0 to 255.

func (*Pixel) String

func (p *Pixel) String() string

type Rect

type Rect struct {
	X      int
	Y      int
	Width  uint
	Height uint
}

type Statistics

type Statistics struct {
	Red     *ChannelStatistics
	Green   *ChannelStatistics
	Blue    *ChannelStatistics
	Opacity *ChannelStatistics
}

type Storage

type Storage C.StorageType

Jump to

Keyboard shortcuts

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