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

@@ -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
}