first version
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"image/png"
|
||||
|
||||
"git.trj.tw/golang/go-watch-webp/module/config"
|
||||
"golang.org/x/image/webp"
|
||||
)
|
||||
|
||||
// ConvertToPng -
|
||||
func ConvertToPng(file io.Reader) error {
|
||||
log.Println("convert func ")
|
||||
conf := config.GetConfig()
|
||||
|
||||
webpImg, err := webp.Decode(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
filename := fmt.Sprintf("%d.png", time.Now().UnixNano())
|
||||
fp := path.Join(conf.Dist, filename)
|
||||
|
||||
target, err := os.Create(fp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := png.Encode(target, webpImg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user