bimg: Index | Files

package bimg

import ""


Package Files

file.go image.go metadata.go options.go resize.go resizer.go type.go version.go vips.go


const (
    // Quality defines the default JPEG quality to be used.
    Quality = 80
    // MaxSize defines the maximum pixels width or height supported.
    MaxSize = 16383
const Version = "1.0.18"

Version represents the current package semantic version.

const VipsMajorVersion = int(C.VIPS_MAJOR_VERSION)

VipsMajorVersion exposes the current libvips major version number

const VipsMinorVersion = int(C.VIPS_MINOR_VERSION)

VipsMinorVersion exposes the current libvips minor version number

const VipsVersion = string(C.VIPS_VERSION)

VipsVersion exposes the current libvips semantic version


var ColorBlack = Color{0, 0, 0}

ColorBlack is a shortcut to black RGB color representation.

var (
    ErrExtractAreaParamsRequired = errors.New("extract area width/height params are required")
var ImageTypes = map[ImageType]string{
    JPEG:   "jpeg",
    PNG:    "png",
    WEBP:   "webp",
    TIFF:   "tiff",
    GIF:    "gif",
    PDF:    "pdf",
    SVG:    "svg",
    MAGICK: "magick",

ImageTypes stores as pairs of image types supported and its alias names.

var SupportedImageTypes = map[ImageType]SupportedImageType{}

SupportedImageTypes stores the optional image type supported by the current libvips compilation. Note: lazy evaluation as demand is required due to bootstrap runtime limitation with C/libvips world.

var WatermarkFont = "sans 10"

WatermarkFont defines the default watermark font to be used.

func ColourspaceIsSupported Uses

func ColourspaceIsSupported(buf []byte) (bool, error)

ColourspaceIsSupported checks if the image colourspace is supported by libvips.

func DetermineImageTypeName Uses

func DetermineImageTypeName(buf []byte) string

DetermineImageTypeName determines the image type format by name (jpeg, png, webp or tiff)

func ImageTypeName Uses

func ImageTypeName(t ImageType) string

ImageTypeName is used to get the human friendly name of an image format.

func Initialize Uses

func Initialize()

Initialize is used to explicitly start libvips in thread-safe way. Only call this function if you have previously turned off libvips.

func IsSVGImage Uses

func IsSVGImage(buf []byte) bool

IsSVGImage returns true if the given buffer is a valid SVG image.

func IsTypeNameSupported Uses

func IsTypeNameSupported(t string) bool

IsTypeNameSupported checks if a given image type name is supported

func IsTypeNameSupportedSave Uses

func IsTypeNameSupportedSave(t string) bool

IsTypeNameSupportedSave checks if a given image type name is supported for saving

func IsTypeSupported Uses

func IsTypeSupported(t ImageType) bool

IsTypeSupported checks if a given image type is supported

func IsTypeSupportedSave Uses

func IsTypeSupportedSave(t ImageType) bool

IsTypeSupportedSave checks if a given image type is support for saving

func Read Uses

func Read(path string) ([]byte, error)

Read reads all the content of the given file path and returns it as byte buffer.

func Resize Uses

func Resize(buf []byte, o Options) ([]byte, error)

Resize is used to transform a given image as byte buffer with the passed options.

func Shutdown Uses

func Shutdown()

Shutdown is used to shutdown libvips in a thread-safe way. You can call this to drop caches as well. If libvips was already initialized, the function is no-op

func VipsCacheDropAll Uses

func VipsCacheDropAll()

VipsCacheDropAll drops the vips operation cache, freeing the allocated memory.

func VipsCacheSetMax Uses

func VipsCacheSetMax(maxCacheSize int)

VipsCacheSetMax sets the maximum number of operations to keep in the vips operation cache.

func VipsCacheSetMaxMem Uses

func VipsCacheSetMaxMem(maxCacheMem int)

VipsCacheSetMaxMem Sets the maximum amount of tracked memory allowed before the vips operation cache begins to drop entries.

func VipsDebugInfo Uses

func VipsDebugInfo()

VipsDebugInfo outputs to stdout libvips collected data. Useful for debugging.

func VipsIsTypeSupported Uses

func VipsIsTypeSupported(t ImageType) bool

VipsIsTypeSupported returns true if the given image type is supported by the current libvips compilation.

func VipsIsTypeSupportedSave Uses

func VipsIsTypeSupportedSave(t ImageType) bool

VipsIsTypeSupportedSave returns true if the given image type is supported by the current libvips compilation for the save operation.

func Write Uses

func Write(path string, buf []byte) error

Write writes the given byte buffer into disk to the given file path.

type Angle Uses

type Angle int

Angle represents the image rotation angle value.

const (
    // D0 represents the rotation angle 0 degrees.
    D0  Angle = 0
    // D45 represents the rotation angle 90 degrees.
    D45 Angle = 45
    // D90 represents the rotation angle 90 degrees.
    D90 Angle = 90
    // D135 represents the rotation angle 90 degrees.
    D135 Angle = 135
    // D180 represents the rotation angle 180 degrees.
    D180 Angle = 180
    // D235 represents the rotation angle 235 degrees.
    D235 Angle = 235
    // D270 represents the rotation angle 270 degrees.
    D270 Angle = 270
    // D315 represents the rotation angle 180 degrees.
    D315 Angle = 315

type Color Uses

type Color struct {
    R, G, B uint8

Color represents a traditional RGB color scheme.

type Direction Uses

type Direction int

Direction represents the image direction value.

const (
    // Horizontal represents the orizontal image direction value.
    Horizontal Direction = C.VIPS_DIRECTION_HORIZONTAL
    // Vertical represents the vertical image direction value.
    Vertical Direction = C.VIPS_DIRECTION_VERTICAL

type Extend Uses

type Extend int

Extend represents the image extend mode, used when the edges of an image are extended, you can specify how you want the extension done. See:

const (
    // ExtendBlack extend with black (all 0) pixels mode.
    ExtendBlack Extend = C.VIPS_EXTEND_BLACK
    // ExtendCopy copy the image edges.
    ExtendCopy Extend = C.VIPS_EXTEND_COPY
    // ExtendRepeat repeat the whole image.
    ExtendRepeat Extend = C.VIPS_EXTEND_REPEAT
    // ExtendMirror mirror the whole image.
    ExtendMirror Extend = C.VIPS_EXTEND_MIRROR
    // ExtendWhite extend with white (all bits set) pixels.
    ExtendWhite Extend = C.VIPS_EXTEND_WHITE
    // ExtendBackground with colour from the background property.
    ExtendBackground Extend = C.VIPS_EXTEND_BACKGROUND
    // ExtendLast extend with last pixel.
    ExtendLast Extend = C.VIPS_EXTEND_LAST

type GaussianBlur Uses

type GaussianBlur struct {
    Sigma   float64
    MinAmpl float64

GaussianBlur represents the gaussian image transformation values.

type Gravity Uses

type Gravity int

Gravity represents the image gravity value.

const (
    // GravityCentre represents the centre value used for image gravity orientation.
    GravityCentre Gravity = iota
    // GravityNorth represents the north value used for image gravity orientation.
    // GravityEast represents the east value used for image gravity orientation.
    // GravitySouth represents the south value used for image gravity orientation.
    // GravityWest represents the west value used for image gravity orientation.
    // GravitySmart enables libvips Smart Crop algorithm for image gravity orientation.

type Image Uses

type Image struct {
    // contains filtered or unexported fields

Image provides a simple method DSL to transform a given image as byte buffer.

func NewImage Uses

func NewImage(buf []byte) *Image

NewImage creates a new Image struct with method DSL.

func (*Image) Colourspace Uses

func (i *Image) Colourspace(c Interpretation) ([]byte, error)

Colourspace performs a color space conversion bsaed on the given interpretation.

func (*Image) ColourspaceIsSupported Uses

func (i *Image) ColourspaceIsSupported() (bool, error)

ColourspaceIsSupported checks if the current image color space is supported.

func (*Image) Convert Uses

func (i *Image) Convert(t ImageType) ([]byte, error)

Convert converts image to another format.

func (*Image) Crop Uses

func (i *Image) Crop(width, height int, gravity Gravity) ([]byte, error)

Crop crops the image to the exact size specified.

func (*Image) CropByHeight Uses

func (i *Image) CropByHeight(height int) ([]byte, error)

CropByHeight crops an image by height (auto width).

func (*Image) CropByWidth Uses

func (i *Image) CropByWidth(width int) ([]byte, error)

CropByWidth crops an image by width only param (auto height).

func (*Image) Enlarge Uses

func (i *Image) Enlarge(width, height int) ([]byte, error)

Enlarge enlarges the image by width and height. Aspect ratio is maintained.

func (*Image) EnlargeAndCrop Uses

func (i *Image) EnlargeAndCrop(width, height int) ([]byte, error)

EnlargeAndCrop enlarges the image by width and height with additional crop transformation.

func (*Image) Extract Uses

func (i *Image) Extract(top, left, width, height int) ([]byte, error)

Extract area from the by X/Y axis in the current image.

func (*Image) Flip Uses

func (i *Image) Flip() ([]byte, error)

Flip flips the image about the vertical Y axis.

func (*Image) Flop Uses

func (i *Image) Flop() ([]byte, error)

Flop flops the image about the horizontal X axis.

func (*Image) ForceResize Uses

func (i *Image) ForceResize(width, height int) ([]byte, error)

ForceResize resizes with custom size (aspect ratio won't be maintained).

func (*Image) Image Uses

func (i *Image) Image() []byte

Image returns the current resultant image buffer.

func (*Image) Interpretation Uses

func (i *Image) Interpretation() (Interpretation, error)

Interpretation gets the image interpretation type. See:

func (*Image) Length Uses

func (i *Image) Length() int

Length returns the size in bytes of the image buffer.

func (*Image) Metadata Uses

func (i *Image) Metadata() (ImageMetadata, error)

Metadata returns the image metadata (size, alpha channel, profile, EXIF rotation).

func (*Image) Process Uses

func (i *Image) Process(o Options) ([]byte, error)

Process processes the image based on the given transformation options, talking with libvips bindings accordingly and returning the resultant image buffer.

func (*Image) Resize Uses

func (i *Image) Resize(width, height int) ([]byte, error)

Resize resizes the image to fixed width and height.

func (*Image) ResizeAndCrop Uses

func (i *Image) ResizeAndCrop(width, height int) ([]byte, error)

ResizeAndCrop resizes the image to fixed width and height with additional crop transformation.

func (*Image) Rotate Uses

func (i *Image) Rotate(a Angle) ([]byte, error)

Rotate rotates the image by given angle degrees (0, 90, 180 or 270).

func (*Image) Size Uses

func (i *Image) Size() (ImageSize, error)

Size returns the image size as form of width and height pixels.

func (*Image) SmartCrop Uses

func (i *Image) SmartCrop(width, height int) ([]byte, error)

SmartCrop produces a thumbnail aiming at focus on the interesting part.

func (*Image) Thumbnail Uses

func (i *Image) Thumbnail(pixels int) ([]byte, error)

Thumbnail creates a thumbnail of the image by the a given width by aspect ratio 4:4.

func (*Image) Trim Uses

func (i *Image) Trim() ([]byte, error)

Trim removes the background from the picture. It can result in a 0x0 output if the image is all background.

func (*Image) Type Uses

func (i *Image) Type() string

Type returns the image type format (jpeg, png, webp, tiff).

func (*Image) Watermark Uses

func (i *Image) Watermark(w Watermark) ([]byte, error)

Watermark adds text as watermark on the given image.

func (*Image) WatermarkImage Uses

func (i *Image) WatermarkImage(w WatermarkImage) ([]byte, error)

WatermarkImage adds image as watermark on the given image.

func (*Image) Zoom Uses

func (i *Image) Zoom(factor int) ([]byte, error)

Zoom zooms the image by the given factor. You should probably call Extract() before.

type ImageMetadata Uses

type ImageMetadata struct {
    Orientation int
    Channels    int
    Alpha       bool
    Profile     bool
    Type        string
    Space       string
    Colourspace string
    Size        ImageSize

ImageMetadata represents the basic metadata fields

func Metadata Uses

func Metadata(buf []byte) (ImageMetadata, error)

Metadata returns the image metadata (size, type, alpha channel, profile, EXIF orientation...).

type ImageSize Uses

type ImageSize struct {
    Width  int
    Height int

ImageSize represents the image width and height values

func Size Uses

func Size(buf []byte) (ImageSize, error)

Size returns the image size by width and height pixels.

type ImageType Uses

type ImageType int

ImageType represents an image type value.

const (
    // UNKNOWN represents an unknow image type value.
    UNKNOWN ImageType = iota
    // JPEG represents the JPEG image type.
    // WEBP represents the WEBP image type.
    // PNG represents the PNG image type.
    // TIFF represents the TIFF image type.
    // GIF represents the GIF image type.
    // PDF represents the PDF type.
    // SVG represents the SVG image type.
    // MAGICK represents the libmagick compatible genetic image type.

func DetermineImageType Uses

func DetermineImageType(buf []byte) ImageType

DetermineImageType determines the image type format (jpeg, png, webp or tiff)

type Interpolator Uses

type Interpolator int

Interpolator represents the image interpolation value.

const (
    // Bicubic interpolation value.
    Bicubic Interpolator = iota
    // Bilinear interpolation value.
    // Nohalo interpolation value.
    // Nearest neighbour interpolation value.

func (Interpolator) String Uses

func (i Interpolator) String() string

type Interpretation Uses

type Interpretation int

Interpretation represents the image interpretation type. See:

const (
    // InterpretationError points to the libvips interpretation error type.
    InterpretationError Interpretation = C.VIPS_INTERPRETATION_ERROR
    // InterpretationMultiband points to its libvips interpretation equivalent type.
    InterpretationMultiband Interpretation = C.VIPS_INTERPRETATION_MULTIBAND
    // InterpretationBW points to its libvips interpretation equivalent type.
    InterpretationBW Interpretation = C.VIPS_INTERPRETATION_B_W
    // InterpretationCMYK points to its libvips interpretation equivalent type.
    InterpretationCMYK Interpretation = C.VIPS_INTERPRETATION_CMYK
    // InterpretationRGB points to its libvips interpretation equivalent type.
    InterpretationRGB Interpretation = C.VIPS_INTERPRETATION_RGB
    // InterpretationSRGB points to its libvips interpretation equivalent type.
    InterpretationSRGB Interpretation = C.VIPS_INTERPRETATION_sRGB
    // InterpretationRGB16 points to its libvips interpretation equivalent type.
    InterpretationRGB16 Interpretation = C.VIPS_INTERPRETATION_RGB16
    // InterpretationGREY16 points to its libvips interpretation equivalent type.
    InterpretationGREY16 Interpretation = C.VIPS_INTERPRETATION_GREY16
    // InterpretationScRGB points to its libvips interpretation equivalent type.
    InterpretationScRGB Interpretation = C.VIPS_INTERPRETATION_scRGB
    // InterpretationLAB points to its libvips interpretation equivalent type.
    InterpretationLAB Interpretation = C.VIPS_INTERPRETATION_LAB
    // InterpretationXYZ points to its libvips interpretation equivalent type.
    InterpretationXYZ Interpretation = C.VIPS_INTERPRETATION_XYZ

func ImageInterpretation Uses

func ImageInterpretation(buf []byte) (Interpretation, error)

ImageInterpretation returns the image interpretation type. See:

type Options Uses

type Options struct {
    Height         int
    Width          int
    AreaHeight     int
    AreaWidth      int
    Top            int
    Left           int
    Quality        int
    Compression    int
    Zoom           int
    Crop           bool
    SmartCrop      bool // Deprecated, use: bimg.Options.Gravity = bimg.GravitySmart
    Enlarge        bool
    Embed          bool
    Flip           bool
    Flop           bool
    Force          bool
    NoAutoRotate   bool
    NoProfile      bool
    Interlace      bool
    StripMetadata  bool
    Trim           bool
    Lossless       bool
    Extend         Extend
    Rotate         Angle
    Background     Color
    Gravity        Gravity
    Watermark      Watermark
    WatermarkImage WatermarkImage
    Type           ImageType
    Interpolator   Interpolator
    Interpretation Interpretation
    GaussianBlur   GaussianBlur
    Sharpen        Sharpen
    Threshold      float64
    OutputICC      string

Options represents the supported image transformation options.

type Sharpen Uses

type Sharpen struct {
    Radius int
    X1     float64
    Y2     float64
    Y3     float64
    M1     float64
    M2     float64

Sharpen represents the image sharp transformation options.

type SupportedImageType Uses

type SupportedImageType struct {
    Load bool
    Save bool

SupportedImageType represents whether a type can be loaded and/or saved by the current libvips compilation.

func IsImageTypeSupportedByVips Uses

func IsImageTypeSupportedByVips(t ImageType) SupportedImageType

IsImageTypeSupportedByVips returns true if the given image type is supported by current libvips compilation.

type VipsMemoryInfo Uses

type VipsMemoryInfo struct {
    Memory          int64
    MemoryHighwater int64
    Allocations     int64

VipsMemoryInfo represents the memory stats provided by libvips.

func VipsMemory Uses

func VipsMemory() VipsMemoryInfo

VipsMemory gets memory info stats from libvips (cache size, memory allocs...)

type Watermark Uses

type Watermark struct {
    Width       int
    DPI         int
    Margin      int
    Opacity     float32
    NoReplicate bool
    Text        string
    Font        string
    Background  Color

Watermark represents the text-based watermark supported options.

type WatermarkImage Uses

type WatermarkImage struct {
    Left    int
    Top     int
    Buf     []byte
    Opacity float32

WatermarkImage represents the image-based watermark supported options.

Package bimg imports 12 packages (graph) and is imported by 7 packages. Updated 2019-01-23. Refresh now. Tools for package owners.