-
Notifications
You must be signed in to change notification settings - Fork 35
/
properties_im.go
53 lines (46 loc) · 995 Bytes
/
properties_im.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
// +build !gm
package magick
// #include <stdlib.h>
// #include <magick/api.h>
import "C"
import (
"unsafe"
)
func (im *Image) properties() []string {
C.ResetImagePropertyIterator(im.image)
var props []string
for {
prop := C.GetNextImageProperty(im.image)
if prop == nil {
break
}
props = append(props, C.GoString(prop))
}
C.ResetImagePropertyIterator(im.image)
return props
}
func (im *Image) destroyProperties() {
C.DestroyImageProperties(im.image)
}
func (im *Image) property(key string) *string {
k := C.CString(key)
prop := C.GetImageProperty(im.image, k)
C.free(unsafe.Pointer(k))
if prop != nil {
s := C.GoString(prop)
return &s
}
return nil
}
func (im *Image) setProperty(key string, value *C.char) bool {
k := C.CString(key)
var ret bool
if value == nil {
ret = C.DeleteImageProperty(im.image, k) != 0
} else {
C.DeleteImageProperty(im.image, k)
ret = C.SetImageProperty(im.image, k, value) != 0
}
C.free(unsafe.Pointer(k))
return ret
}