forked from rainycape/magick
/
annotate.go
33 lines (24 loc) · 903 Bytes
/
annotate.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
// +build gm
package magick
// #include <string.h>
// #include <magick/api.h>
import "C"
import "unsafe"
func (im *Image) AnnotateImage(x, y int, text string, fontSize int, color string){
image_info := C.CloneImageInfo(nil)
defer C.DestroyImageInfo(image_info);
draw_info := C.CloneDrawInfo(image_info, nil)
defer C.DestroyDrawInfo(draw_info)
textBytes := []byte(text)
bytesPointer := unsafe.Pointer(&textBytes[0])
textArray := (*C.uchar)(bytesPointer)
colorArray := C.CString(color)
defer C.free(unsafe.Pointer(colorArray))
draw_context := C.DrawAllocateContext(draw_info, im.image)
defer C.DrawDestroyContext(draw_context)
C.DrawSetFontSize(draw_context, C.double(fontSize))
C.DrawSetStrokeColorString(draw_context, colorArray)
C.DrawSetFillColorString(draw_context, colorArray)
C.DrawAnnotation(draw_context, C.double(x), C.double(y), textArray)
C.DrawRender(draw_context)
}