Golang Achieve image watermark effect

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

  Original Image:


Add a watermark after the image:

//golang image watermark Processing//non-implementation of web uploads and other code ...//sam//2013.6.19//http://zituo.netpackage mainimport ("FMT" "Image" "Image/draw" " Image/jpeg "" Image/png "" OS ") Func main () {///original picture is SAM.JPGIMGB, _: = OS. Open ("Sam.jpg") img, _: = JPEG. Decode (IMGB) defer IMGB. Close () WMB, _: = OS. Open ("Text.png") watermark, _: = png. Decode (WMB) defer WMB. Close ()//write the watermark to the lower right corner, and offset to 0 coordinates of 10 pixels: = 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)//generate new picture new.jpg, and set picture quality. IMGW, _: = OS. Create ("new.jpg") jpeg. Encode (IMGW, M, &jpeg. OPTIONS{100}) Defer IMGW. Close () fmt. PRINTLN ("Watermark added end, see new.jpg Pictures ...")} 

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.