Skip to content

Commit

Permalink
GIF support added to Save function. Go version 1.2+ is now required.'
Browse files Browse the repository at this point in the history
  • Loading branch information
disintegration committed Nov 8, 2014
1 parent 02226dd commit c317ebd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"image"
"image/color"
_ "image/gif"
"image/gif"
"image/jpeg"
"image/png"
"math"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit c317ebd

Please sign in to comment.