Skip to content

Commit

Permalink
Replace lossypng to goquant. Bye-bye Go 1.5 (for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladyslav Yarema committed Jan 22, 2017
1 parent 989a626 commit aa8dfeb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dist: trusty
language: go

go:
- 1.5
#- 1.5
- 1.6
- 1.7

Expand Down
21 changes: 3 additions & 18 deletions transform.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package imgwizard

import (
"bytes"
"image"
"image/png"
"net/http"

"github.com/foobaz/lossypng/lossypng"
"github.com/shifr/goquant"
"github.com/shifr/vips"
)

func Transform(img_buff *[]byte, ctx *Context) {
var err error
buf := new(bytes.Buffer)

debug("Detecting image type...")
iType := http.DetectContentType(*img_buff)
Expand All @@ -29,18 +25,7 @@ func Transform(img_buff *[]byte, ctx *Context) {
}

if iType == PNG && !ctx.Options.Webp {
decoded, _, err := image.Decode(bytes.NewReader(*img_buff))
if err != nil {
warning("Can't decode PNG image, reason - %s", err)
}

out := lossypng.Compress(decoded, lossypng.NoConversion, 100-ctx.Options.Quality)
err = png.Encode(buf, out)
if err != nil {
warning("Can't encode PNG image, reason - %s", err)
}

*img_buff = buf.Bytes()
goquant.Quantize(img_buff)
debug("NEW IMAGE SIZE: %d", len(*img_buff))
}

}

0 comments on commit aa8dfeb

Please sign in to comment.