You can add watermarks to your images for brand promotion and publicity. This helps protect the copyrights of images and prevent unauthorized use of images. Edge Security Acceleration (ESA) allows you to add text watermarks or image watermarks to specified parts of images and adjust the transparency of the watermarks to ensure that both the watermarks and image content are clearly displayed.
Parameters
image_process=watermark
Basic parameters (watermark positions)
Parameter | Description | Value range |
t | The opacity of the text or image watermark. |
Default value: |
g | The position of the watermark on the image. |
|
x | The horizontal margin that specifies the horizontal distance between the watermark and the image edge. This parameter takes effect only if the watermark is on the upper left, middle left, lower left, upper right, middle right, or lower right of the image. |
Default value: |
y | The vertical margin that specifies the vertical distance between the watermark and the image edge. This parameter takes effect only if the watermark is on the upper-left, upper middle, upper right, lower left, lower middle, or lower-right of the image. |
Default value: |
You can use x, y, and offset to adjust the position of a watermark on an image. You can also use these parameters to adjust the watermark layout when the image has multiple watermarks.
Image watermark parameters
Parameter | Description | Value range |
image | The watermark URL that is accessible over the Internet. If authentication or permissions are required to access the specified URL, ESA may fail to retrieve the watermark URL. Watermark URLs must be Base64-encoded. For more information, see Encode watermarks. | Base64-encoded strings |
Text watermark parameters
Parameter | Description | Value range |
text | The content of the text watermark. The text content must be Base64-encoded. For more information, see Encode watermarks. | A Base64-encoded string that contains at most 60 characters in length |
type | The font of the text watermark. The font name must be Base64-encoded. For more information, see Encode watermarks. | You can specify up to 10 fonts. For information about fonts and font encoding, see type settings and encoding. |
color | The color of the text watermark. The valid values for this parameter are RGB color values. | For example, 000000 specifies black, and FFFFFF specifies white. Default value: |
rotate | The degree by which the text watermark is rotated clockwise. |
Default value: |
fill | Specifies whether to tile the base image with the text watermark. | Valid values:
|
size | The size of the text watermark. |
Default value: Unit: |
type settings and encoding
Text font | Description | Encoded value |
alihyaihei | A bold font. This is the default font. | YWxpaHlhaWhlaQ |
hysong | A Songti font variant. | aHlzb25n |
hyhei | A Heiti font variant. | aHloZWk |
hyshuangxian | A double line font. | aHlzaHVhbmd4aWFu |
fzltzhk | A Heiti font variant. | ZnpsdHpoaw |
fzshengsks | A regular script font. | ZnpzaGVuZ3Nrcw |
fzqusongjian | A Songti font variant. | ZnpxdXNvbmdqaWFu |
zzgfxingyan | An artistic font. | enpnZnhpbmd5YW4 |
comfortaa | Comfortaa | Y29tZm9ydGFh |
notosans | NotoSans | bm90b3NhbnM |
If you use a font that is not included in the 10 fonts, the font is recognized as the default font alihyaihei
.
Encode watermarks
When you add watermarks, you must encode the content and fonts of the text images or encode the URLs of the image watermarks in Base64 by using characters that are allowed in URLs. To encode watermarks, perform the following steps:
Encode the watermark content in Base64.
We recommend that you use URL-safe Base64 encoding tools to encode the content and fonts of text watermarks and URLs of the image watermarks. Base64-encoded watermark content is applicable to only watermark-specific parameters. Do not include Base64-encoded watermark content in signature strings.
Replace characters in the Base64-encoded watermark content based on the following rules:
Replace the plus signs (
+
) with hyphens (-
).Replace the forward slashes (
/
) with underscores (_
).Omit the equal signs (
=
) at the end of the Base64-encoded watermark content.
Examples
Add the "Hello World" text watermark.
Encode the Hello World
text watermark in Base64 by using characters that are allowed in URLs. For more information, see Encode watermarks. The encoding result of the text watermark is SGVsbG8gV29ybGQ
. The encoding result of the hysong font is aHlzb25n
. The image processing URL is http(s)://example.com/image01.png?image_process=watermark,text_SGVsbG8gV29ybGQ,type_aHlzb25n
.
Add text and image watermarks.
Encode the "Happy New Year" text watermark in Base64 into the
5paw5bm05b-r5LmQ
string by using characters that are allowed in URLs. Set the position of the text watermark to lower right, the horizontal margin to 10 pixels, and the vertical offset from the middle line to 10 pixels by usingg_se,x_10,y_10
.Encode the
http://example-test.oss-ap-southeast-1.aliyuncs.com/image/shuiyin.png
image watermark URL in Base64 into theaHR0cDovL2V4YW1wbGUtdGVzdC5vc3MtYXAtc291dGhlYXN0LTEuYWxpeXVuY3MuY29tL2ltYWdlL3NodWl5aW4ucG5n
string by using characters that are allowed in URLs. Set the position of the image watermark to upper left, the horizontal margin to 10 pixels, and the vertical offset from the middle line to 10 pixels by usingg_nw,x_10,y_10
.Specify the image processing URL as
http(s)://example.com/image01.png?image_process=watermark,text_5paw5bm05b-r5LmQ,g_se,x_10,y_10/watermark,image_aHR0cDovL2V4YW1wbGUtdGVzdC5vc3MtYXAtc291dGhlYXN0LTEuYWxpeXVuY3MuY29tL2ltYWdlL3NodWl5aW4ucG5n,g_nw,x_10,y_10
.