Skip to content
Newer
Older
100644 52 lines (39 sloc) 1.03 KB
c5366e5 @tobi Rewrote jpg code in terms of type composition
authored
1 package mogrify
2
a7a2688 @tobi Move encode to package level
authored
3 import ()
c5366e5 @tobi Rewrote jpg code in terms of type composition
authored
4
5 type GdImage struct {
8924dc7 @tobi register image formats centrally
authored
6 gd *gdImage
c5366e5 @tobi Rewrote jpg code in terms of type composition
authored
7 }
8
9 func NewImage(width, height int) Image {
8924dc7 @tobi register image formats centrally
authored
10 var image GdImage
11 image.gd = gdCreate(width, height)
12 if image.gd == nil {
13 return nil
14 }
c5366e5 @tobi Rewrote jpg code in terms of type composition
authored
15
8924dc7 @tobi register image formats centrally
authored
16 return &image
c5366e5 @tobi Rewrote jpg code in terms of type composition
authored
17 }
18
fe030e7 @tobi Use Bounds rather then int as parameters to resize functions
authored
19 func (img *GdImage) NewResized(bounds Bounds) (*GdImage, error) {
8924dc7 @tobi register image formats centrally
authored
20 resized := img.image().gdCopyResized(0, 0, 0, 0, bounds.Width, bounds.Height, img.image().width(), img.image().height())
21 if resized == nil {
22 return nil, resampleError
23 }
c5366e5 @tobi Rewrote jpg code in terms of type composition
authored
24
8924dc7 @tobi register image formats centrally
authored
25 return &GdImage{resized}, nil
c5366e5 @tobi Rewrote jpg code in terms of type composition
authored
26 }
27
fe030e7 @tobi Use Bounds rather then int as parameters to resize functions
authored
28 func (img *GdImage) NewResampled(bounds Bounds) (*GdImage, error) {
8924dc7 @tobi register image formats centrally
authored
29 resized := img.image().gdCopyResampled(0, 0, 0, 0, bounds.Width, bounds.Height, img.image().width(), img.image().height())
30 if resized == nil {
31 return nil, resampleError
32 }
c5366e5 @tobi Rewrote jpg code in terms of type composition
authored
33
8924dc7 @tobi register image formats centrally
authored
34 return &GdImage{resized}, nil
c5366e5 @tobi Rewrote jpg code in terms of type composition
authored
35 }
36
11ce6af @tobi Added Bounds as own struct
authored
37 func (img *GdImage) Bounds() Bounds {
8924dc7 @tobi register image formats centrally
authored
38 return Bounds{img.image().width(), img.image().height()}
c5366e5 @tobi Rewrote jpg code in terms of type composition
authored
39 }
40
41 func (img *GdImage) Height() int {
8924dc7 @tobi register image formats centrally
authored
42 return img.image().height()
c5366e5 @tobi Rewrote jpg code in terms of type composition
authored
43 }
44
45 func (img *GdImage) image() *gdImage {
8924dc7 @tobi register image formats centrally
authored
46 return img.gd
c5366e5 @tobi Rewrote jpg code in terms of type composition
authored
47 }
48
49 func (img *GdImage) Destroy() {
8924dc7 @tobi register image formats centrally
authored
50 img.image().gdDestroy()
c5366e5 @tobi Rewrote jpg code in terms of type composition
authored
51 }
Something went wrong with that request. Please try again.