Avatar downloader

This commit is contained in:
2017-06-12 20:06:31 +02:00
parent 72857972fe
commit 586befcb1a
9 changed files with 185 additions and 6 deletions

40
jobs/avatars/webp.go Normal file
View File

@ -0,0 +1,40 @@
package main
import (
"fmt"
"image"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"os"
"github.com/chai2010/webp"
)
func convertFileToWebP(in string, out string, quality float32) error {
f, openErr := os.Open(in)
if openErr != nil {
return openErr
}
img, format, decodeErr := image.Decode(f)
if decodeErr != nil {
return decodeErr
}
fmt.Println(format, img.Bounds().Dx(), img.Bounds().Dy())
fileOut, writeErr := os.Create(out)
if writeErr != nil {
return writeErr
}
encodeErr := webp.Encode(fileOut, img, &webp.Options{
Quality: quality,
})
return encodeErr
}