Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Gif/Png encoding

  • Loading branch information...
commit 4ea46cf740d9cf036ee1038b03145f0c838195d7 1 parent a7a2688
@tobi authored
Showing with 35 additions and 0 deletions.
  1. +17 −0 gd.go
  2. +18 −0 image.go
View
17 gd.go
@@ -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
18 image.go
@@ -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)
+}
Please sign in to comment.
Something went wrong with that request. Please try again.