Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

encoding deserves it's own package

  • Loading branch information...
commit 278b33e362807b9269fa995f807ae806a6c21e5a 1 parent 4ea46cf
@tobi authored
Showing with 33 additions and 29 deletions.
  1. +33 −0 encoding.go
  2. +0 −29 image.go
View
33 encoding.go
@@ -0,0 +1,33 @@
+package mogrify
+
+import (
+ "bytes"
+ "io"
+)
+
+func EncodeJpg(w io.Writer, img Image) (int64, error) {
+ slice, err := img.image().gdImageJpeg()
+ if err != nil {
+ return 0, err
+ }
+
+ 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)
+}
View
29 image.go
@@ -1,10 +1,8 @@
package mogrify
import (
- "bytes"
"errors"
"fmt"
- "io"
)
var (
@@ -27,30 +25,3 @@ type Image interface {
func Dimensions(img Image) string {
return fmt.Sprintf("%dx%d", img.Width(), img.Height())
}
-
-func EncodeJpg(w io.Writer, img Image) (int64, error) {
- slice, err := img.image().gdImageJpeg()
- if err != nil {
- return 0, err
- }
-
- 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.