govips

package module
v0.0.0-...-3bc26dd Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 11 Imported by: 0

README

Vips for Go

GoDoc Report Card

This package is powered by the libvips image processing library, originally created in 1989 at Birkbeck College and currently maintained by John Cupitt.

Prerequisites

Installation

go get github.com/bandlab/govips

Install libvips on Mac OS

brew install homebrew/science/vips --with-imagemagick --with-webp

Install libvips on Linux

TODO

Usage

In your own code:

import "github.com/bandlab/govips"

...
govips.Initialize();
...

From the command line (go install github.com/bandlab/govips/cli):

cli -r 300x300 -q 90 -fast-resize -v path/to/input.jpg path/to/output.jpg

Roadmap

  • Documentation
  • Tests

Author

Rob Cherry (original fork) Andrew Watts (this fork, for BandLab (GitHub))

Contributing

Contributions welcome! Please fork the repository and open a pull request with your changes.

Notes

The provided sRGB ICC profile is from icc-profiles-free

The provided CMYK ICM profile is from Argyll Color Management System

Documentation

Index

Constants

View Source
const (
	INT_ZERO    = -1
	FLOAT_ZERO  = -1.0
	STRING_ZERO = "GOVIPS_STRING_ZERO"

	DEFAULT_CONCURRENCY      = 0
	DEFAULT_CACHE_MAX        = 1000
	DEFAULT_CACHE_MAX_FILES  = 100
	DEFAULT_CACHE_MAX_MEMORY = 100 * 1024 * 1024
)

Special constants used to signify a zero value instead of the default value.

View Source
const (
	JPEG_QUANTIZATION_TABLE_DEFAULT int = 0
	JPEG_QUANTIZATION_TABLE_FLAT
	JPEG_QUANTIZATION_TABLE_MSSIM
	JPEG_QUANTIZATION_TABLE_IMAGEMAGICK
	JPEG_QUANTIZATION_TABLE_PSNR_HVS_M
)
View Source
const (
	VIPS_INTENT_PERCEPTUAL = iota
	VIPS_INTENT_RELATIVE
	VIPS_INTENT_SATURATION
	VIPS_INTENT_ABSOLUTE
	VIPS_INTENT_LAST
)

Variables

View Source
var (
	ErrInitialize = errors.New("Failed to initialize libvips")
	ErrConfigure  = errors.New("Failed to configure libvips")

	ErrLoad = errors.New("Failed to load image")
	ErrSave = errors.New("Failed to save image")

	ErrEmbed        = errors.New("Failed to embed image")
	ErrCrop         = errors.New("Failed to crop image")
	ErrShrink       = errors.New("Failed to shrink image")
	ErrReduce       = errors.New("Failed to reduce image")
	ErrResize       = errors.New("Failed to resize image")
	ErrAffine       = errors.New("Failed to affine image")
	ErrBlur         = errors.New("Failed to blur image")
	ErrSharpen      = errors.New("Failed to sharpen image")
	ErrFlatten      = errors.New("Failed to flatten image")
	ErrColourspace  = errors.New("Failed to convert colourspace of image")
	ErrICCTransform = errors.New("Failed to transform colourspace of image")
)
View Source
var (
	VIPS_BACKGROUND_BLACK = []float64{0}
	VIPS_BACKGROUND_WHITE = []float64{255}
)

Functions

func ColourspaceIsSupported

func ColourspaceIsSupported(v *VipsImage) bool

func Configure

func Configure(config Config) error

func EncodeJpegBytes

func EncodeJpegBytes(i *VipsImage, options *EncodeJpegOptions) ([]byte, error)

func EncodeJpegFile

func EncodeJpegFile(i *VipsImage, file *os.File, options *EncodeJpegOptions) error

func EncodePngBytes

func EncodePngBytes(i *VipsImage, options *EncodePngOptions) ([]byte, error)

func EncodePngFile

func EncodePngFile(i *VipsImage, file *os.File, options *EncodePngOptions) error

func EncodeWebpBytes

func EncodeWebpBytes(i *VipsImage, options *EncodeWebpOptions) ([]byte, error)

func EncodeWebpFile

func EncodeWebpFile(i *VipsImage, file *os.File, options *EncodeWebpOptions) error

func ErrorBuffer

func ErrorBuffer() error

func Initialize

func Initialize() error

func InitializeWithConfig

func InitializeWithConfig(config Config) error

func Shutdown

func Shutdown()

func ThreadShutdown

func ThreadShutdown()

Types

type AffineOptions

type AffineOptions struct {
	Interpolate *VipsInterpolate
	OArea       []int
	Idx         float64
	Idy         float64
	Odx         float64
	Ody         float64
}

type BlurOptions

type BlurOptions struct {
	Precision        VipsPrecision
	MinimumAmplitude float64
}

type CMYKVipsImage

type CMYKVipsImage struct {
	*VipsImage
	// contains filtered or unexported fields
}

func NewCMYKVipsImage

func NewCMYKVipsImage(vi *VipsImage) (*CMYKVipsImage, error)

func (*CMYKVipsImage) At

func (v *CMYKVipsImage) At(x, y int) color.Color

func (*CMYKVipsImage) ColorModel

func (v *CMYKVipsImage) ColorModel() color.Model

func (*CMYKVipsImage) Free

func (v *CMYKVipsImage) Free()

type ColourspaceOptions

type ColourspaceOptions struct {
	SourceSpace VipsInterpretation
}

type Config

type Config struct {
	Concurrency    int
	CacheMax       int
	CacheMaxFiles  int
	CacheMaxMemory int
}

type DecodeGifOptions

type DecodeGifOptions struct {
	DecodeOptions
	Page int
}

type DecodeJpegOptions

type DecodeJpegOptions struct {
	DecodeOptions
	Shrink     int
	Fail       bool
	Autorotate bool
}

type DecodeMagickOptions

type DecodeMagickOptions struct {
	DecodeOptions
	AllFrames bool
	Density   string
	Page      int
}

type DecodeOptions

type DecodeOptions struct {
	Access VipsAccess
	Disc   bool
}

type DecodeWebpOptions

type DecodeWebpOptions struct {
	DecodeOptions
	Shrink int
}

type EmbedOptions

type EmbedOptions struct {
	Extend     VipsExtend
	Background []float64
}

type EncodeJpegOptions

type EncodeJpegOptions struct {
	Q                   int
	Profile             string
	OptimizeCoding      bool
	Interlace           bool
	Strip               bool
	NoSubsample         bool
	TrellisQuantization bool
	OvershootDeringing  bool
	OptimizeScans       bool
	QuantizationTable   int
}

type EncodePngOptions

type EncodePngOptions struct {
	Compression int
	Interlace   bool
	Profile     string
	Filter      PngFilter
}

type EncodeWebpOptions

type EncodeWebpOptions struct {
	Q              int
	Lossless       bool
	Preset         WebpPreset
	SmartSubsample bool
	NearLossless   bool
	AlphaQ         int
}

type FlattenOptions

type FlattenOptions struct {
	Background []float64
	MaxAlpha   float64
}

type GrayVipsImage

type GrayVipsImage struct {
	*VipsImage
	// contains filtered or unexported fields
}

func NewGrayVipsImage

func NewGrayVipsImage(vi *VipsImage) (*GrayVipsImage, error)

func (*GrayVipsImage) At

func (v *GrayVipsImage) At(x, y int) color.Color

func (*GrayVipsImage) ColorModel

func (v *GrayVipsImage) ColorModel() color.Model

func (*GrayVipsImage) Free

func (v *GrayVipsImage) Free()

type ICCTransformOptions

type ICCTransformOptions struct {
	InputProfile string
	Intent       VipsIntent
	Depth        int
	Embedded     bool
}

type NRGBAVipsImage

type NRGBAVipsImage struct {
	*VipsImage
	// contains filtered or unexported fields
}

func NewNRGBAVipsImage

func NewNRGBAVipsImage(vi *VipsImage) (*NRGBAVipsImage, error)

func (*NRGBAVipsImage) At

func (v *NRGBAVipsImage) At(x, y int) color.Color

func (*NRGBAVipsImage) ColorModel

func (v *NRGBAVipsImage) ColorModel() color.Model

func (*NRGBAVipsImage) Free

func (v *NRGBAVipsImage) Free()

type PngFilter

type PngFilter int
const (
	VIPS_PNG_FILTER_DEFAULT PngFilter = iota
	VIPS_PNG_FILTER_NONE
	VIPS_PNG_FILTER_SUB
	VIPS_PNG_FILTER_UP
	VIPS_PNG_FILTER_AVG
	VIPS_PNG_FILTER_PAETH
	VIPS_PNG_FILTER_ALL
)

type SharpenOptions

type SharpenOptions struct {
	Sigma float64
	X1    float64
	Y2    float64
	Y3    float64
	M1    float64
	M2    float64
}

type SimilarityOptions

type SimilarityOptions struct {
	Scale       float64
	Angle       float64
	Interpolate *VipsInterpolate
	Idx         float64
	Idy         float64
	Odx         float64
	Ody         float64
}

type VipsAccess

type VipsAccess int
const (
	VIPS_ACCESS_RANDOM VipsAccess = iota
	VIPS_ACCESS_SEQUENTIAL
	VIPS_ACCESS_SEQUENTIAL_UNBUFFERED
	VIPS_ACCESS_LAST
)

type VipsExtend

type VipsExtend int
const (
	VIPS_EXTEND_BLACK VipsExtend = iota
	VIPS_EXTEND_COPY
	VIPS_EXTEND_REPEAT
	VIPS_EXTEND_MIRROR
	VIPS_EXTEND_WHITE
	VIPS_EXTEND_BACKGROUND
)

type VipsImage

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

func Affine

func Affine(v *VipsImage, a, b, c, d float64, options *AffineOptions) (*VipsImage, error)

func Blur

func Blur(v *VipsImage, sigma float64, options *BlurOptions) (*VipsImage, error)

func Colourspace

func Colourspace(v *VipsImage, space VipsInterpretation, options *ColourspaceOptions) (*VipsImage, error)

func Crop

func Crop(v *VipsImage, left, top, width, height int) (*VipsImage, error)

func DecodeGifBytes

func DecodeGifBytes(b []byte, options *DecodeGifOptions) (*VipsImage, error)

func DecodeGifReader

func DecodeGifReader(r io.Reader, options *DecodeGifOptions) (*VipsImage, error)

func DecodeJpegBytes

func DecodeJpegBytes(b []byte, options *DecodeJpegOptions) (*VipsImage, error)

func DecodeJpegReader

func DecodeJpegReader(r io.Reader, options *DecodeJpegOptions) (*VipsImage, error)

func DecodeMagickBytes

func DecodeMagickBytes(b []byte, options *DecodeMagickOptions) (*VipsImage, error)

func DecodeMagickReader

func DecodeMagickReader(r io.Reader, options *DecodeMagickOptions) (*VipsImage, error)

func DecodePngBytes

func DecodePngBytes(b []byte, options *DecodeOptions) (*VipsImage, error)

func DecodePngReader

func DecodePngReader(r io.Reader, options *DecodeOptions) (*VipsImage, error)

func DecodeWebpBytes

func DecodeWebpBytes(b []byte, options *DecodeWebpOptions) (*VipsImage, error)

func DecodeWebpReader

func DecodeWebpReader(r io.Reader, options *DecodeWebpOptions) (*VipsImage, error)

func Embed

func Embed(v *VipsImage, x, y, width, height int, options *EmbedOptions) (*VipsImage, error)

func ExtractArea

func ExtractArea(v *VipsImage, left, top, width, height int) (*VipsImage, error)

func Flatten

func Flatten(v *VipsImage, options *FlattenOptions) (*VipsImage, error)

func ICCTransform

func ICCTransform(v *VipsImage, outputProfile string, options *ICCTransformOptions) (*VipsImage, error)

func Reduce

func Reduce(v *VipsImage, xshrink, yshrink float64, kernel VipsKernel) (*VipsImage, error)

func ReduceH

func ReduceH(v *VipsImage, xshrink float64, kernel VipsKernel) (*VipsImage, error)

func ReduceV

func ReduceV(v *VipsImage, yshrink float64, kernel VipsKernel) (*VipsImage, error)

func Resize

func Resize(v *VipsImage, scale, vscale float64, kernel VipsKernel) (*VipsImage, error)

func Sharpen

func Sharpen(v *VipsImage, options *SharpenOptions) (*VipsImage, error)

func Shrink

func Shrink(v *VipsImage, xshrink, yshrink float64) (*VipsImage, error)

func ShrinkH

func ShrinkH(v *VipsImage, xshrink float64) (*VipsImage, error)

func ShrinkV

func ShrinkV(v *VipsImage, yshrink float64) (*VipsImage, error)

func Similarity

func Similarity(v *VipsImage, options *SimilarityOptions) (*VipsImage, error)

func (*VipsImage) Bands

func (v *VipsImage) Bands() int

func (*VipsImage) Bounds

func (v *VipsImage) Bounds() image.Rectangle

func (*VipsImage) Free

func (v *VipsImage) Free()

func (*VipsImage) HasProfile

func (v *VipsImage) HasProfile() bool

func (*VipsImage) Interpretation

func (v *VipsImage) Interpretation() VipsInterpretation

func (*VipsImage) RemoveProfile

func (v *VipsImage) RemoveProfile()

type VipsIntent

type VipsIntent int

type VipsInterpolate

type VipsInterpolate struct {
	Nickname string
	// contains filtered or unexported fields
}

func NewBicubicVipsInterpolator

func NewBicubicVipsInterpolator() *VipsInterpolate

func NewBilinearVipsInterpolator

func NewBilinearVipsInterpolator() *VipsInterpolate

func NewLBBVipsInterpolator

func NewLBBVipsInterpolator() *VipsInterpolate

func NewNearestVipsInterpolator

func NewNearestVipsInterpolator() *VipsInterpolate

func NewNohaloVipsInterpolator

func NewNohaloVipsInterpolator() *VipsInterpolate

func NewVSQBSVipsInterpolator

func NewVSQBSVipsInterpolator() *VipsInterpolate

func NewVipsInterpolator

func NewVipsInterpolator(interpolator string) (*VipsInterpolate, error)

func (*VipsInterpolate) Free

func (i *VipsInterpolate) Free()

type VipsInterpretation

type VipsInterpretation int
const (
	VIPS_INTERPRETATION_ERROR     VipsInterpretation = C.VIPS_INTERPRETATION_ERROR
	VIPS_INTERPRETATION_MULTIBAND VipsInterpretation = C.VIPS_INTERPRETATION_MULTIBAND
	VIPS_INTERPRETATION_B_W       VipsInterpretation = C.VIPS_INTERPRETATION_B_W
	VIPS_INTERPRETATION_HISTOGRAM VipsInterpretation = C.VIPS_INTERPRETATION_HISTOGRAM
	VIPS_INTERPRETATION_XYZ       VipsInterpretation = C.VIPS_INTERPRETATION_XYZ
	VIPS_INTERPRETATION_LAB       VipsInterpretation = C.VIPS_INTERPRETATION_LAB
	VIPS_INTERPRETATION_CMYK      VipsInterpretation = C.VIPS_INTERPRETATION_CMYK
	VIPS_INTERPRETATION_LABQ      VipsInterpretation = C.VIPS_INTERPRETATION_LABQ
	VIPS_INTERPRETATION_RGB       VipsInterpretation = C.VIPS_INTERPRETATION_RGB
	VIPS_INTERPRETATION_CMC       VipsInterpretation = C.VIPS_INTERPRETATION_CMC
	VIPS_INTERPRETATION_LCH       VipsInterpretation = C.VIPS_INTERPRETATION_LCH
	VIPS_INTERPRETATION_LABS      VipsInterpretation = C.VIPS_INTERPRETATION_LABS
	VIPS_INTERPRETATION_sRGB      VipsInterpretation = C.VIPS_INTERPRETATION_sRGB
	VIPS_INTERPRETATION_YXY       VipsInterpretation = C.VIPS_INTERPRETATION_YXY
	VIPS_INTERPRETATION_FOURIER   VipsInterpretation = C.VIPS_INTERPRETATION_FOURIER
	VIPS_INTERPRETATION_RGB16     VipsInterpretation = C.VIPS_INTERPRETATION_RGB16
	VIPS_INTERPRETATION_GREY16    VipsInterpretation = C.VIPS_INTERPRETATION_GREY16
	VIPS_INTERPRETATION_MATRIX    VipsInterpretation = C.VIPS_INTERPRETATION_MATRIX
	VIPS_INTERPRETATION_scRGB     VipsInterpretation = C.VIPS_INTERPRETATION_scRGB
	VIPS_INTERPRETATION_HSV       VipsInterpretation = C.VIPS_INTERPRETATION_HSV
	VIPS_INTERPRETATION_LAST      VipsInterpretation = C.VIPS_INTERPRETATION_LAST
)

type VipsKernel

type VipsKernel int
const (
	VIPS_KERNEL_NEAREST VipsKernel = iota
	VIPS_KERNEL_LINEAR
	VIPS_KERNEL_CUBIC
	VIPS_KERNEL_LANCZOS2
	VIPS_KERNEL_LANCZOS3
	VIPS_KERNEL_LAST
)

type VipsPrecision

type VipsPrecision int
const (
	VIPS_PRECISION_INTEGER VipsPrecision = iota
	VIPS_PRECISION_FLOAT
	VIPS_PRECISION_APPROXIMATE
	VIPS_PRECISION_LAST
)

type WebpPreset

type WebpPreset int
const (
	VIPS_WEBP_PRESET_DEFAULT WebpPreset = iota
	VIPS_WEBP_PRESET_PICTURE
	VIPS_WEBP_PRESET_PHOTO
	VIPS_WEBP_PRESET_DRAWING
	VIPS_WEBP_PRESET_ICON
	VIPS_WEBP_PRESET_TEXT
	VIPS_WEBP_PRESET_LAST
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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