golang webp图片转jpg

package main

import (
    "bytes"
    "image/jpeg"
    "io/ioutil"
    "log"
    "os"

    "github.com/chai2010/webp"
)

func main() {
    // var buf bytes.Buffer
    var data []byte
    var err error

    // Load file data
    if data, err = ioutil.ReadFile("./aaaa.webp"); err != nil {
        log.Println(err)
    }

    // Decode webp
    m, err := webp.Decode(bytes.NewReader(data))
    if err != nil {
        log.Println(err)
    }

    //生成新图片new.jpg,并设置图片质量..
    imgw, _ := os.Create("./aaaa.jpg")
    jpeg.Encode(imgw, m, &jpeg.Options{100})

}

golang为图片添加水印

//SetSY 一个图片添加水印
func SetSY(logo, tp string) {
    //原始图片是sam.jpg
    imgb, err := os.Open(tp)
    if err != nil {
        fmt.Println("打开图片失败")
        return
    }
    img, format1, err := image.Decode(imgb)
    if err != nil {
        fmt.Println("解码图片失败-", format1, err.Error())
        return
    }
    defer imgb.Close()

    wmb, err := os.Open(logo)
    if err != nil {
        fmt.Println("打开Logo失败")
        return
    }
    watermark, format2, err := image.Decode(wmb)
    if err != nil {
        fmt.Println("解码Logo失败-", format2, err.Error())
        return
    }

    defer wmb.Close()

    //把水印写到右下角,并向0坐标各偏移10个像素
    offset := image.Pt(img.Bounds().Dx()-watermark.Bounds().Dx()-10, img.Bounds().Dy()-watermark.Bounds().Dy()-10)
    b := img.Bounds()
    m := image.NewNRGBA(b)

    draw.Draw(m, b, img, image.ZP, draw.Src)
    draw.Draw(m, watermark.Bounds().Add(offset), watermark, image.ZP, draw.Over)

    //生成新图片new.jpg,并设置图片质量..
    imgw, _ := os.Create(tp)
    jpeg.Encode(imgw, m, &jpeg.Options{100})

    defer imgw.Close()

    fmt.Println("添加水印成功...")
}