-
Notifications
You must be signed in to change notification settings - Fork 35
/
properties_gm.go
51 lines (44 loc) · 997 Bytes
/
properties_gm.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
// +build gm
package magick
// #include <stdlib.h>
// #include <magick/api.h>
import "C"
import (
"unsafe"
)
func (im *Image) properties() []string {
prop := C.GetImageAttribute(im.image, nil)
var props []string
for prop != nil {
if prop.key != nil {
s := C.GoString(prop.key)
props = append(props, s)
}
prop = (*C.ImageAttribute)(prop.next)
}
return props
}
func (im *Image) destroyProperties() {
C.DestroyImageAttributes(im.image)
}
func (im *Image) property(key string) *string {
k := C.CString(key)
prop := C.GetImageAttribute(im.image, k)
C.free(unsafe.Pointer(k))
if prop != nil && prop.value != nil {
s := C.GoString(prop.value)
return &s
}
return nil
}
func (im *Image) setProperty(key string, value *C.char) bool {
if value != nil {
// Clear the property first, otherwise GM concatenates
// the values
im.setProperty(key, nil)
}
k := C.CString(key)
ret := C.SetImageAttribute(im.image, k, value)
C.free(unsafe.Pointer(k))
return ret != 0
}