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 ¶
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 VipsDetectMemoryLeak(on bool)
- 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 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 VipsDetectMemoryLeak ¶
func VipsDetectMemoryLeak(on bool)
VipsDetectMemoryLeak turn on/off memory leak reports
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 copy data to VipsBlob 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 GVipsImage ¶
func GVipsImage() *GValue
GVipsImage return gValue, contains new empty *C.VipsImage.
Calling Copy() at empty *C.VipsImage will return error.
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. It unset gValue after call, so for next call you get nil value 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 Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
Operation wrapper around *C.VipsOperation 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. This arguments will be freed after call *Operation.Free()