write output as jpeg as option
This commit is contained in:
2
gopow.go
2
gopow.go
@@ -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",
|
||||
|
||||
@@ -3,6 +3,7 @@ package gopow
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"os"
|
||||
"time"
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user