I want to find something about making the watermark image examples, written in Go language!
I need a PNG image for the watermark image, that can be applied to other formats PNG, GIF, JPEG etc.,
I hope you can give me some practical examples.
As already mentioned, you can watermark images with the image/draw package.
Here's a quick practical example, adding a transparent png image to a jpeg image and saving as jpeg:
package main
import (
"image"
"image/draw"
"image/jpeg"
"image/png"
"os"
)
func main() {
imgb, _ := os.Open("image.jpg")
img, _ := jpeg.Decode(imgb)
defer imgb.Close()
wmb, _ := os.Open("watermark.png")
watermark, _ := png.Decode(wmb)
defer wmb.Close()
offset := image.Pt(200, 200)
b := img.Bounds()
m := image.NewRGBA(b)
draw.Draw(m, b, img, image.ZP, draw.Src)
draw.Draw(m, watermark.Bounds().Add(offset), watermark, image.ZP, draw.Over)
imgw, _ := os.Create("watermarked.jpg")
jpeg.Encode(imgw, m, &jpeg.Options{jpeg.DefaultQuality})
defer imgw.Close()
}
image.jpg:
watermark.png:
result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With