-
Notifications
You must be signed in to change notification settings - Fork 35
/
decorate.go
60 lines (56 loc) · 1.37 KB
/
decorate.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
package magick
// #include <magick/api.h>
import "C"
func (im *Image) AddBorder(r Rect, c *Pixel) (*Image, error) {
return im.Apply(func(i *Image) (*Image, error) {
var ex C.ExceptionInfo
C.GetExceptionInfo(&ex)
defer C.DestroyExceptionInfo(&ex)
var b *Pixel
if c != nil {
b = i.BorderColor()
im.SetBorderColor(c)
}
bordered := C.BorderImage(i.image, r.rectangleInfo(), &ex)
if b != nil {
i.SetBorderColor(b)
}
if bordered == nil {
return nil, exError(&ex, "adding border")
}
return newImage(bordered, nil), nil
})
}
func (im *Image) AddFrame(f Frame, c *Pixel) (*Image, error) {
return im.Apply(func(i *Image) (*Image, error) {
var ex C.ExceptionInfo
C.GetExceptionInfo(&ex)
defer C.DestroyExceptionInfo(&ex)
var m *Pixel
if c != nil {
m = i.MatteColor()
i.SetMatteColor(c)
}
framed := C.FrameImage(i.image, f.frameInfo(), &ex)
if m != nil {
i.SetMatteColor(m)
}
if framed == nil {
return nil, exError(&ex, "adding border")
}
return newImage(framed, nil), nil
})
}
func (im *Image) Raise(r Rect, threedimensional bool) (*Image, error) {
// RaiseImage modifies the image, use a clone
cloned, err := im.Clone()
if err != nil {
return nil, err
}
flag := magickBool(threedimensional)
rect := r.rectangleInfo()
return cloned.Apply(func(i *Image) (*Image, error) {
C.RaiseImage(i.image, rect, flag)
return i, nil
})
}