write output as jpeg as option

This commit is contained in:
David Högborg
2015-07-17 12:48:13 +02:00
parent da11b94d0b
commit bfcc7c72ac
2 changed files with 18 additions and 2 deletions

View File

@@ -66,7 +66,7 @@ func main() {
cli.StringFlag{ cli.StringFlag{
Name: "format,f", Name: "format,f",
Value: "png", Value: "png",
Usage: "Output file format, default png", Usage: "Output file format, default png [png,jpeg]",
}, },
cli.BoolFlag{ cli.BoolFlag{
Name: "verbose", Name: "verbose",

View File

@@ -3,6 +3,7 @@ package gopow
import ( import (
"fmt" "fmt"
"image" "image"
"image/jpeg"
"image/png" "image/png"
"os" "os"
"time" "time"
@@ -108,7 +109,22 @@ func (g *GoPow) Write() error {
return err return err
} }
err = png.Encode(out, g.image) switch g.config.Format {
case "png":
err = png.Encode(out, g.image)
break
case "jpeg", "jpg":
opt := &jpeg.Options{
Quality: 98,
}
err = jpeg.Encode(out, g.image, opt)
break
default:
return fmt.Errorf("unsupported format: %s", g.config.Format)
}
if err != nil { if err != nil {
return err return err
} }