Documentation
¶
Overview ¶
Package imgvips provides low-level bindings for libvips: https://github.com/libvips/libvips. For better shooting to the leg.
Implements VipsOperation(https://libvips.github.io/libvips/API/current/VipsOperation.html) builder, which allows you to call most of the existing image operations in the library.
Example ¶
nolint:funlen // For testing
package main import ( "errors" "log" "github.com/Arimeka/imgvips" ) func main() { op, err := imgvips.NewOperation("webpload") if err != nil { log.Println(err) return } defer op.Free() out := imgvips.GNullVipsImage() op.AddInput("filename", imgvips.GString("./tests/fixtures/img.webp")) op.AddInput("scale", imgvips.GDouble(0.1)) op.AddOutput("out", out) if err := op.Exec(); err != nil { log.Println(err) return } resizeOp, err := imgvips.NewOperation("resize") if err != nil { log.Println(err) return } defer resizeOp.Free() image, ok := out.Image() if !ok { log.Println(errors.New("out is not *C.VipsImage")) return } w := image.Width() h := image.Height() hScale := float64(350) / float64(h) wScale := float64(650) / float64(w) resizeOut := imgvips.GNullVipsImage() resizeOp.AddInput("in", out) resizeOp.AddInput("scale", imgvips.GDouble(wScale)) resizeOp.AddInput("vscale", imgvips.GDouble(hScale)) resizeOp.AddOutput("out", resizeOut) if err := resizeOp.Exec(); err != nil { log.Println(err) return } saveOp, err := imgvips.NewOperation("webpsave") if err != nil { log.Println(err) return } defer saveOp.Free() saveOp.AddInput("in", resizeOut) saveOp.AddInput("filename", imgvips.GString("./tests/fixtures/resized.webp")) saveOp.AddInput("Q", imgvips.GInt(50)) saveOp.AddInput("strip", imgvips.GBoolean(true)) if err := saveOp.Exec(); err != nil { log.Println(err) return } }
Output:
Index ¶
- Variables
- func GetAllocs() float64
- func GetMem() float64
- func GetMemHighwater() float64
- func Initialize(options ...InitOption) error
- func VipsErrorFree()
- type Argument
- type GValue
- func (v *GValue) Boolean() (value, ok bool)
- func (v *GValue) Bytes() (value []byte, ok bool)
- func (v *GValue) Copy() (*GValue, error)
- func (v *GValue) Double() (value float64, ok bool)
- func (v *GValue) Free()
- func (v *GValue) Image() (value *Image, ok bool)
- func (v *GValue) Int() (value int, ok bool)
- func (v *GValue) Ptr() unsafe.Pointer
- func (v *GValue) String() (value string, ok bool)
- type Image
- type InitOption
- type Operation
- type Value
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCopyForbidden returns when GValue forbid copy function ErrCopyForbidden = errors.New("copy forbidden for this type") )
var ( // ErrOperationAlreadyFreed operation already call Free() ErrOperationAlreadyFreed = errors.New("operation already freed") )
Functions ¶
func GetAllocs ¶ added in v0.2.0
func GetAllocs() float64
GetAllocs return libvips tracked number of active allocations
func GetMemHighwater ¶ added in v0.2.0
func GetMemHighwater() float64
GetMemHighwater return libvips tracked memory high-water
func Initialize ¶ added in v0.2.0
func Initialize(options ...InitOption) error
Initialize libvips
By default, libvips cache will be turned off (set to zero), vector arithmetic - turned on.
Types ¶
type Argument ¶
type Argument struct {
// contains filtered or unexported fields
}
Argument contains key-gValue for set it to *C.VipsOperation
type GValue ¶
type GValue struct {
// contains filtered or unexported fields
}
GValue contains glib gValue and its type
func GNullVipsBlob ¶
func GNullVipsBlob() *GValue
GNullVipsBlob create empty glib object gValue with type for *C.VipsBlob Calling Copy() at GValue with type VipsBlob is forbidden.
func GNullVipsImage ¶
func GNullVipsImage() *GValue
GNullVipsImage create empty glib object gValue with type for *C.VipsImage.
Calling Copy() at empty *C.VipsImage will return error.
func GVipsBlob ¶
GVipsBlob create VipsBlob from bytes array.
You must protect bytes array from GC and modification while using the VipsImage loaded from this blob.
VipsBlob is used in load_buffer and save_buffer. VipsBlob is a boxed type, so we use g_value_set_boxed instead of g_value_set_object.
Calling Copy() at GValue with type VipsBlob is forbidden.
func (*GValue) Boolean ¶
Boolean return boolean gValue, if type is GBoolean. If type not match, ok will return false. If gValue already freed, gValue will be false, ok will be true.
func (*GValue) Bytes ¶
Bytes return bytes slice from GValue.
If type not match, ok will return false. If VipsBlob already freed, return nil value, ok will be true.
func (*GValue) Double ¶
Double return float64 gValue, if type is GDouble. If type not match, ok will return false. If gValue already freed, gValue will be 0, ok will be true.
func (*GValue) Image ¶
Image return *Image, if type is *C.VipsImage.
If type not match, ok will return false. If gValue already freed, gValue will be nil, ok will be true.
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image wrapper around *C.VipsImage
type InitOption ¶ added in v0.2.0
type InitOption struct {
// contains filtered or unexported fields
}
InitOption specifies an option for initialize libvips
func VipsCacheSetMax ¶ added in v0.2.0
func VipsCacheSetMax(n int) InitOption
VipsCacheSetMax set maximum number of operation to cache
func VipsCacheSetMaxMem ¶ added in v0.2.0
func VipsCacheSetMaxMem(n int) InitOption
VipsCacheSetMaxMem set maximum amount of tracked memory
func VipsConcurrencySet ¶ added in v0.2.0
func VipsConcurrencySet(n int) InitOption
VipsConcurrencySet set number of threads to use
func VipsDetectMemoryLeak ¶
func VipsDetectMemoryLeak(on bool) InitOption
VipsDetectMemoryLeak turn on/off memory leak reports
func VipsVectorSetEnables ¶ added in v0.2.0
func VipsVectorSetEnables(enabled bool) InitOption
VipsVectorSetEnables enable fast vector path based on half-float arithmetic
type Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
Operation wrapper around *C.VipsOperation.
It contains separates arguments for set to operation and arguments to return from operation.
func NewOperation ¶
NewOperation initialize new *C.VipsOperation.
If libvips don't known operation with provided name, function return error.
func (*Operation) AddInput ¶
AddInput adds argument for set to operation.
After call *Operation.Exec(), all values from input arguments will be freed.
func (*Operation) AddOutput ¶
AddOutput adds argument for get from operation.
After call Exec(), all values from output arguments will be updated from operation result. These arguments will be freed after call *Operation.Free()