Skip to content
Newer
Older
100644 32 lines (24 sloc) 448 Bytes
8c4321f @tobi Complete encoding/decoding for the three major formats
authored May 29, 2012
1 package mogrify
2
3 import (
8924dc7 @tobi register image formats centrally
authored Jun 1, 2012
4 "bytes"
5 "io"
8c4321f @tobi Complete encoding/decoding for the three major formats
authored May 30, 2012
6 )
7
8 type Png struct {
8924dc7 @tobi register image formats centrally
authored Jun 1, 2012
9 // Import GdImage and all it's methods
10 GdImage
8c4321f @tobi Complete encoding/decoding for the three major formats
authored May 30, 2012
11 }
12
13 func DecodePng(reader io.Reader) Image {
8924dc7 @tobi register image formats centrally
authored Jun 1, 2012
14 var image Png
8c4321f @tobi Complete encoding/decoding for the three major formats
authored May 30, 2012
15
8924dc7 @tobi register image formats centrally
authored Jun 1, 2012
16 image.gd = gdCreateFromPng(drain(reader))
17 if image.gd == nil {
18 return nil
19 }
8c4321f @tobi Complete encoding/decoding for the three major formats
authored May 30, 2012
20
8924dc7 @tobi register image formats centrally
authored Jun 1, 2012
21 return &image
8c4321f @tobi Complete encoding/decoding for the three major formats
authored May 30, 2012
22 }
23
24 func EncodePng(w io.Writer, img Image) (int64, error) {
8924dc7 @tobi register image formats centrally
authored Jun 1, 2012
25 slice, err := img.image().gdImagePng()
26 if err != nil {
27 return 0, err
28 }
8c4321f @tobi Complete encoding/decoding for the three major formats
authored May 30, 2012
29
8924dc7 @tobi register image formats centrally
authored Jun 1, 2012
30 return bytes.NewBuffer(slice).WriteTo(w)
8c4321f @tobi Complete encoding/decoding for the three major formats
authored May 30, 2012
31 }
Something went wrong with that request. Please try again.