/
gd_image.go
51 lines (39 loc) · 1.03 KB
/
gd_image.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
package mogrify
import ()
type GdImage struct {
gd *gdImage
}
func NewImage(width, height int) Image {
var image GdImage
image.gd = gdCreate(width, height)
if image.gd == nil {
return nil
}
return &image
}
func (img *GdImage) NewResized(bounds Bounds) (*GdImage, error) {
resized := img.image().gdCopyResized(0, 0, 0, 0, bounds.Width, bounds.Height, img.image().width(), img.image().height())
if resized == nil {
return nil, resampleError
}
return &GdImage{resized}, nil
}
func (img *GdImage) NewResampled(bounds Bounds) (*GdImage, error) {
resized := img.image().gdCopyResampled(0, 0, 0, 0, bounds.Width, bounds.Height, img.image().width(), img.image().height())
if resized == nil {
return nil, resampleError
}
return &GdImage{resized}, nil
}
func (img *GdImage) Bounds() Bounds {
return Bounds{img.image().width(), img.image().height()}
}
func (img *GdImage) Height() int {
return img.image().height()
}
func (img *GdImage) image() *gdImage {
return img.gd
}
func (img *GdImage) Destroy() {
img.image().gdDestroy()
}