Skip to content

Commit

Permalink
write output as jpeg as option
Browse files Browse the repository at this point in the history
  • Loading branch information
dhogborg committed Jul 17, 2015
1 parent da11b94 commit bfcc7c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gopow.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func main() {
cli.StringFlag{
Name: "format,f",
Value: "png",
Usage: "Output file format, default png",
Usage: "Output file format, default png [png,jpeg]",
},
cli.BoolFlag{
Name: "verbose",
Expand Down
18 changes: 17 additions & 1 deletion internal/gopow/gopow.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gopow
import (
"fmt"
"image"
"image/jpeg"
"image/png"
"os"
"time"
Expand Down Expand Up @@ -108,7 +109,22 @@ func (g *GoPow) Write() error {
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 {
return err
}
Expand Down

0 comments on commit bfcc7c7

Please sign in to comment.