1
0
Эх сурвалжийг харах

GIF support added to Save function. Go version 1.2+ is now required.'

disintegration 11 жил өмнө
parent
commit
c317ebdc7a
2 өөрчлөгдсөн 8 нэмэгдсэн , 4 устгасан
  1. 3 1
      README.md
  2. 5 3
      helpers.go

+ 3 - 1
README.md

@@ -5,6 +5,8 @@ This package is based on the standard Go image package and works best along with
 
 ## Installation
 
+Imaging requires Go version 1.2 or greater.
+
     go get -u github.com/disintegration/imaging
 
 *[Git](http://git-scm.com/) and [Mercurial](http://mercurial.selenic.com/) are needed.*
@@ -172,7 +174,7 @@ dstImage = imaging.Invert(srcImage)
 #### Open, Save, New, Clone
 
 Imaging package provides useful shortcuts for image loading, saving, creation and copying.
-Open and Save functions support JPEG, PNG, TIFF and BMP images. 
+Open and Save functions support JPEG, PNG, TIFF, BMP and GIF images. 
 External libraries can be used to load other image formats.
 
 ```go

+ 5 - 3
helpers.go

@@ -4,7 +4,7 @@ import (
 	"fmt"
 	"image"
 	"image/color"
-	_ "image/gif"
+	"image/gif"
 	"image/jpeg"
 	"image/png"
 	"math"
@@ -34,11 +34,11 @@ func Open(filename string) (img image.Image, err error) {
 }
 
 // Save saves the image to file with the specified filename.
-// The format is determined from the filename extension: "jpg" (or "jpeg"), "png", "tif" (or "tiff") and "bmp" are supported.
+// The format is determined from the filename extension: "jpg" (or "jpeg"), "png", "tif" (or "tiff"), "bmp" and "gif" are supported.
 func Save(img image.Image, filename string) (err error) {
 	format := strings.ToLower(filepath.Ext(filename))
 	okay := false
-	for _, ext := range []string{".jpg", ".jpeg", ".png", ".tif", ".tiff", ".bmp"} {
+	for _, ext := range []string{".jpg", ".jpeg", ".png", ".tif", ".tiff", ".bmp", ".gif"} {
 		if format == ext {
 			okay = true
 			break
@@ -78,6 +78,8 @@ func Save(img image.Image, filename string) (err error) {
 		err = tiff.Encode(file, img, &tiff.Options{Compression: tiff.Deflate, Predictor: true})
 	case ".bmp":
 		err = bmp.Encode(file, img)
+	case ".gif":
+		err = gif.Encode(file, img, nil)
 	}
 	return
 }