Golang image-Type watermark processing

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. //golang图片式水印处理 //未实现Web上传等代码... //sam //2013.6.19 //http://zituo.net package main import (      "fmt"      "image"      "image/draw"      "image/jpeg"      "image/png"      "os" ) func main() {      //原始图片是sam.jpg      imgb, _ := os.Open("sam.jpg")      img, _ := jpeg.Decode(imgb)      defer imgb.Close()      wmb, _ := os.Open("text.png")      watermark, _ := png.Decode(wmb)      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("new.jpg")      jpeg.Encode(imgw, m, &jpeg.Options{100})      defer imgw.Close()      fmt.Println("水印添加结束,请查看new.jpg图片...") }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.