image

package
v0.0.0-...-99c152a Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const KernelMKS2021 vips.Kernel = 7

KernelMKS2021 is Magic Kernel Sharp 2021, added in libvips 8.15 govips doesn't export this yet, so we define it here. Value 7 corresponds to VIPS_KERNEL_MKS2021 in libvips.

Variables

This section is empty.

Functions

func InitVips

func InitVips()

InitVips initializes the vips library. Call once at startup. Log level defaults to error. Set ANSEL_LOG_LEVEL env var to change: error, warning, info, debug

func ParseColor

func ParseColor(s string) (color.Color, error)

ParseColor parses a color string into a color.Color. Supports hex colors (#RGB, #RRGGBB, #RRGGBBAA) and named colors.

func ReadIPTCHeadline

func ReadIPTCHeadline(path string) string

ReadIPTCHeadline extracts the IPTC headline from an image file. It first checks for a DXO PhotoLab sidecar file (.dop), then falls back to embedded IPTC metadata in the image. Returns empty string if no headline is found or on error.

func ShutdownVips

func ShutdownVips()

ShutdownVips cleans up vips resources. Call before exit.

Types

type Color

type Color = color.Color

Color is an alias for the standard library color.Color interface.

type Filter

type Filter int

Filter represents a resampling filter type.

const (
	// Lanczos is a high-quality filter, good for downscaling.
	Lanczos Filter = iota
	// CatmullRom is a cubic filter with good sharpness.
	CatmullRom
	// Bilinear is a fast, simple filter.
	Bilinear
	// MagicKernelSharp2021 is the gold-standard resizing filter used by Facebook/Instagram.
	// It combines the Magic Kernel with optimized sharpening for superior results.
	MagicKernelSharp2021
)

func ParseFilter

func ParseFilter(s string) (Filter, error)

ParseFilter converts a string to a Filter type.

func (Filter) String

func (f Filter) String() string

String returns the filter name.

type VipsImage

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

VipsImage wraps a govips image reference.

func LoadVips

func LoadVips(path string) (*VipsImage, error)

LoadVips loads an image using libvips.

func LoadVipsBuffer

func LoadVipsBuffer(data []byte) (*VipsImage, error)

LoadVipsBuffer loads an image from memory. Embedded RAW previews arrive as bytes on a pipe, never as a file on disk.

func (*VipsImage) AddFrame

func (v *VipsImage) AddFrame(top, right, bottom, left int, c color.Color) error

AddFrame adds a colored frame around the image.

func (*VipsImage) AddLabel

func (v *VipsImage) AddLabel(text, font string, fontSize int, offsetX, imageBottomY, paddingY int) error

AddLabel renders a text label on the image with a white background. Font should be in Pango format, e.g. "sans 24" or "Arial Bold 18". fontSize is the point size used in the font string (needed for positioning). offsetX is the X position where the image starts (left edge alignment). imageBottomY is the Y position where the image ends (bottom edge). paddingY is the vertical padding between image bottom and label top.

func (*VipsImage) AddUniformFrame

func (v *VipsImage) AddUniformFrame(width int, c color.Color) error

AddUniformFrame adds a uniform frame on all sides.

func (*VipsImage) Close

func (v *VipsImage) Close()

Close releases the image resources.

func (*VipsImage) Grayscale

func (v *VipsImage) Grayscale() (pix []byte, width, height int, err error)

Grayscale returns one luminance byte per pixel.

The pixels are taken straight from vips memory rather than round-tripped through JPEG. That matters for analysis: JPEG re-encoding introduces high-frequency ringing, which is precisely the signal a sharpness measurement is looking for, so a re-encoded frame would score as sharper than it is.

func (*VipsImage) Height

func (v *VipsImage) Height() int

Height returns the image height.

func (*VipsImage) ResizeToFit

func (v *VipsImage) ResizeToFit(maxWidth, maxHeight int, filter Filter) error

ResizeToFit resizes to fit within the given dimensions, maintaining aspect ratio.

func (*VipsImage) Save

func (v *VipsImage) Save(path string, quality int) error

Save saves the image, detecting format from extension.

func (*VipsImage) SaveJPEG

func (v *VipsImage) SaveJPEG(path string, quality int) error

SaveJPEG saves the image as JPEG.

func (*VipsImage) Width

func (v *VipsImage) Width() int

Width returns the image width.

Jump to

Keyboard shortcuts

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