Watermarking Images
This document helps you understand image watermarks.
Operation Scenarios
ZOS supports image watermarks and text watermarks to protect the ownership of images.
Constraints and Restrictions
Image watermarks can only be in the JPG, PNG, WebP, and TIFF formats.
The size of a source image cannot exceed 20 MB. The width or height cannot exceed 30,000 px, and total pixels cannot exceed 250 million px.
Watermark preprocessing does not support the "|" splicing operator.
Image watermarks and the source image must be in the same bucket.
Description
Operator: watermark
Parameters for adding an image or text watermark must be URL Base64 encoded. Encoding steps: Encode the content to Base64 and replace the code in the result.
Basic Parameters
Parameter Name | Purpose | Value | Required |
t | Transparency of an image or text watermark | [0,100] | No |
x | Horizontal distance from the image edge | [0,4096] | No |
y | Vertical distance from the image edge | [0,4096] | No |
g | Specifies the watermark position on the image. | nw: top-left (default) | No |
Different positions and their reference points are shown in the diagram below.
Watermarking Images Parameters
Parameter Name | Purpose | Value | Required |
image | Specifies the object name of the watermark image. | Base64-encoded string | Yes |
Example
Set the general transparency value t to 50 after watermarking.
Direct Processing
Assume the watermark image is shuiyin.png in the same bucket as the source image, the content to be encoded is "shuiyin.png" and the encoded string is c2h1aXlpbi5wbmc=. The specific request is:
image/watermark, image_c2h1aXlpbi5wbmc=, t_50
Preprocess Watermark
Use the image shuiyin.png. To scale the watermark by 50% and rotate it 180°, Base64 encode shuiyin.png?x-zos-process=image/resize,p_50/rotate,180. After encoding, the result is:
c2h1aXlpbi5wbmc/eC16b3MtcHJvY2Vzcz1pbWFnZS9yZXNpemUscF81MC9yb3RhdGUsMTgw
Replace "/" in the above result with "_". Final request:
image/watermark,image_c2h1aXlpbi5wbmc_eC16b3MtcHJvY2Vzcz1pbWFnZS9yZXNpemUscF81MC9yb3RhdGUsMTgw,t_50
Text Watermark Parameters
Parameter Name | Purpose | Value | Required |
text | Specifies the text watermark content. | Base64-encoded string, with "/" in the encoded result replaced by "_". | Yes |
color | Specifies the color of the text watermark. | RGB color value | No |
size | Specifies the font size of the text watermark. | Default value: 40 | No |
type | Specifies the font type of the text watermark. | Supported English fonts, such as Arial | No |
rotate | Specifies the clockwise rotation angle of the text watermark. | [0,360] | No |
Example
Add the text "Chinatelecom" to the image as a watermark, specify the Heiti font, and set the color to red (FF0000). Set the font size to 40, add it to the bottom right of the source image, and set the opacity to 80. The encoded result of "Chinatelecom" is Q2hpbmF0ZWxlY29t. The specific request is:
image/watermark,text_Q2hpbmF0ZWxlY29t,type_heiti,color_FF0000,size_40,g_se,t_80
FAQ
1. What are the common color codes?
A:
#FFFFFF — White
#0000FF — Blue
#FF0000 — Red
#00FF00 — Green
#808080 — Gray
#FFFF00 — Yellow
#000000 — Black
2. Can I add a background color while adding an image watermark?
A: No.
3. How can I use a local image as a watermark image?
A: Upload the local image to the same bucket as the source image to be watermarked.