-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvip.go
64 lines (52 loc) · 1.3 KB
/
vip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package vips
/*
#cgo pkg-config: vips
#include "vips.h"
*/
import "C"
import (
"errors"
"fmt"
"runtime"
"unsafe"
)
// DefaultInit init vips by default
func DefaultInit() {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if err := Init(); err != nil {
Shutdown()
panic(fmt.Sprintf("unable to start vips! err: %s", err.Error()))
}
}
// Init starts up libvips
func Init() (err error) {
name := C.CString("vipsimage")
defer C.free(unsafe.Pointer(name))
if C.vips_init(name) != 0 {
return Error()
}
return
}
// Shutdown drop caches and close plugins. Run with "--vips-leak" to do a leak check too.
func Shutdown() {
C.vips_shutdown()
}
// LeakSet turn on or off vips leak checking
func LeakSet(leak bool) {
C.vips_leak_set(btoi(leak))
}
// VersionString get the VIPS version as a static string,
// including a build date and time. Do not free.
func VersionString() string {
return C.GoString(C.vips_version_string())
}
// Version get the major, minor or micro library version, with flag values 0, 1 and 2.
func Version(flag int) int {
return int(C.vips_version(C.int(flag)))
}
// Error Get a pointer to the start of the error buffer as a C string.
// The string is owned by the error system and must not be freed.
func Error() error {
return errors.New(C.GoString(C.vips_error_buffer()))
}