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{
|
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",
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user