tencent cloud

All product documents
Cloud Object Storage
Blind Watermark
Last updated: 2024-02-02 15:51:37
Blind Watermark
Last updated: 2024-02-02 15:51:37

Overview

This document provides an overview of APIs and SDK code samples for blind watermarking.
API
Description
Adds a blind watermark to or extracts a blind watermark from a local image and uploads the image to a bucket.

Adding Blind Watermark

Feature description

You can add a blind watermark when uploading or downloading an object.

Sample 1: Adding a blind watermark during upload

opt := &cos.ObjectPutOptions{
nil,
&cos.ObjectPutHeaderOptions{
XOptionHeader: &http.Header{},
},
}
pic := &cos.PicOperations{
IsPicInfo: 1,
Rules: []cos.PicOperationsRules{
{
FileId: ".jpg",
Rule: "watermark/3/type/3/text/" + base64.StdEncoding.EncodeToString([]byte("testwatermark")),
},
},
}
opt.XOptionHeader.Add("Pic-Operations", cos.EncodePicOperations(pic))
name := "test.jpg"
filepath := "./test.jpg"
res, _, err := c.CI.PutFromFile(context.Background(), name, filepath, opt)

Sample 2: Adding a blind watermark during download

name = "test.jpg"
filepath := "watermark.jpg"
_, err = c.CI.GetToFile(context.Background(), name, filepath, "watermark/3/type/3/text/"+base64.StdEncoding.EncodeToString([]byte("testwatermark")), nil)

Extracting Blind Watermark

The request for extracting a blind watermark is the same as that used to simply upload a file to COS, except that you need to add the image processing parameter Pic-Operations to the request header and use the blind watermark extraction parameter watermark/4.

Sample request

opt := &cos.ObjectPutOptions{
nil,
&cos.ObjectPutHeaderOptions{
XOptionHeader: &http.Header{},
},
}
pic := &cos.PicOperations{
IsPicInfo: 1,
Rules: []cos.PicOperationsRules{
{
FileId: "format2.jpg",
Rule: "watermark/4/type/3/text/" + base64.StdEncoding.EncodeToString([]byte("testwatermark")),
},
},
}
opt.XOptionHeader.Add("Pic-Operations", cos.EncodePicOperations(pic))
name := "test2.jpg"
_, err := c.Object.PutFromFile(context.Background(), name, filepath, opt)
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon