Permalink
Browse files

Add Gif/Png encoding

  • Loading branch information...
1 parent a7a2688 commit 4ea46cf740d9cf036ee1038b03145f0c838195d7 @tobi committed May 30, 2012
Showing with 35 additions and 0 deletions.
  1. +17 −0 gd.go
  2. +18 −0 image.go
View
@@ -134,6 +134,23 @@ func (p *gdImage) gdImagePng() ([]byte, error) {
return C.GoBytes(data, size), nil
}
+func (p *gdImage) gdImageGif() ([]byte, error) {
+ if p == nil {
+ panic(imageError)
+ }
+
+ var size C.int
+
+ data := C.gdImageGifPtr(p.img, &size)
+ if data == nil || int(size) == 0 {
+ return []byte{}, writeError
+ }
+
+ defer C.gdFree(unsafe.Pointer(data))
+
+ return C.GoBytes(data, size), nil
+}
+
func (p *gdImage) gdImageJpeg() ([]byte, error) {
if p == nil {
panic(imageError)
View
@@ -36,3 +36,21 @@ func EncodeJpg(w io.Writer, img Image) (int64, error) {
return bytes.NewBuffer(slice).WriteTo(w)
}
+
+func EncodePng(w io.Writer, img Image) (int64, error) {
+ slice, err := img.image().gdImagePng()
+ if err != nil {
+ return 0, err
+ }
+
+ return bytes.NewBuffer(slice).WriteTo(w)
+}
+
+func EncodeGif(w io.Writer, img Image) (int64, error) {
+ slice, err := img.image().gdImageGif()
+ if err != nil {
+ return 0, err
+ }
+
+ return bytes.NewBuffer(slice).WriteTo(w)
+}

0 comments on commit 4ea46cf

Please sign in to comment.