Dynamic Route for CDN (DCDN) supports picture watermarks and text watermarks. You can add picture watermarks and text watermarks to images. This topic describes how to add watermarks to images and provides examples.

Note
  • To enable image editing, submit a ticket.
  • Image editing is a paid service. It is currently free of charge until further notice.

Picture watermarks

Set the action to watermark.

The following table describes the parameters.
Note
  • You cannot resize picture watermarks. The size of a base picture that is used as the watermark cannot exceed 1 MB.
  • You can add at most five watermarks to an image. Picture watermarks and text watermarks are supported.
FeatureDescriptionParameterValid value
Watermark URLYou can specify watermark URLs that are accessible from the Internet. If authentication or permissions are required to access the specified URL, DCDN may fail to retrieve the watermark.

Watermark URLs must be encoded in Base64. For more information, see Watermark encoding.

imageA Base64-encoded string.
Examples
  • Add picture watermarks
    example.com/image01.png?image_process=watermark,image_Base64-encoded image URL,x_20,y_20,g_se,t_70
  • Add picture watermarks and text watermarks
    example.com/image01.png?image_process=watermark,text_Base64-encoded text content,x_10,y_10,g_nw,size_24,color_FF0000,t_70/watermark,image_Base64-encoded image URL,x_20,y_20,g_se,t_70

Text watermarks

Set the action to watermark.

The following table describes the parameters.
Note You can add at most five watermarks to an image. Picture watermarks and text watermarks are supported.
FeatureDescriptionParameterValid value
Text contentSpecifies the content of a text watermark. The text content must be encoded in Base64. For more information, see Watermark encoding. textA Base64-encoded string that contains at most 60 characters in length.
Text fontSpecifies the font of a text watermark. The font name must be encoded in Base64. For more information, see Watermark encoding. typeUp to 10 fonts are supported. For more information, see Text fonts.
Note If you use a font that is not included in the 10 fonts, the font is recognized as the default font alihyaihei.
Text colorSpecifies the color of a text watermark. colorRGB color codes. For example, 000000 represents black and FFFFFF represents white.

Default value: 000000.

Text rotationSpecifies the angle to which the text is rotated clockwise. rotateSupported angles are 90°, 180°, and 270°.
Text tilingSpecifies whether to tile an image with text watermarks. fillValid values: 0 and 1. Default value: 0.
  • 0: does not tile an image with text watermarks.
  • 1: tiles an image with text watermarks.
Examples
  • Add text watermarks
    example.com/image01.png?image_process=watermark,text_Base64-encoded text content,type_YWxpaHlhaWhlaQ,x_10,y_10,g_se,size_24,color_FF0000,t_70,rotate_45,fill_0
  • Add picture watermarks and text watermarks
    example.com/image01.png?image_process=watermark,text_Base64-encoded text content,x_10,y_10,g_nw,size_24,color_FF0000,t_70/watermark,image_Base64-encoded image URL,x_20,y_20,g_se,t_70
The following table describes the text fonts that are supported by text watermarks.
Table 1. Text fonts
Text fontDescriptionCode
alihyaiheiA bold font. This is the default font.YWxpaHlhaWhlaQ
hysongA Songti font variant.aHlzb25n
hyheiA Heiti font variant.aHloZWk
hyshuangxianA double line font.aHlzaHVhbmd4aWFu
fzltzhkA Heiti font variant.ZnpsdHpoaw
fzshengsksA regular script font.ZnpzaGVuZ3Nrcw
fzqusongjianA Songti font variant.ZnpxdXNvbmdqaWFu
zzgfxingyanAn artistic font.enpnZnhpbmd5YW4
comfortaaComfortaaY29tZm9ydGFh
notosansNotoSansbm90b3NhbnM

Watermark positions

Picture watermarks and text watermarks can be positioned by a 3 by 3 grid and Cartesian coordinates (x,y). You can use the 3 by 3 grid and Cartesian coordinates to adjust the position of each watermark. This way, you can manage the layout of watermarks. The following figure shows the positions of watermarks based on a 3 by 3 grid and Cartesian coordinates. Watermark positions
ParameterDescriptionValid value
tSpecifies the opacity of the text or image watermark. [0,100]

Default value: 100, which indicates that the watermark is opaque.

gSpecifies the position of the watermark on the image.
  • nw: upper-left
  • north: upper-center
  • ne: upper-right
  • west: center-left
  • center: center
  • east: center-right
  • sw: lower-left
  • south: lower-center
  • se: lower-right
For more information about the positions, see the preceding figure.
xSpecifies the horizontal margin, which is the horizontal distance between the watermark and the left edge of the image. This parameter takes effect only when the watermark is on the upper-left, center-left, lower-left, upper-right, center-right, or lower-right side of the image. [0,4096]

Default value: 10. Unit: pixels.

ySpecifies the vertical margin, which is the vertical distance between the watermark and the lower edge of the image. This parameter takes effect only when the watermark is on the upper-left, center-left, lower-left, upper-right, center-right, or lower-right side of the image. [0,4096]

Default value: 10. Unit: pixels.

Watermark encoding

When you add watermarks to an image, the content, color, and font of text watermarks and the name of picture watermarks must be URL-encoded in Base64. The encoding method is:

  1. Encode the content in Base64.

    We recommend that you use URL-safe Baes64 encoding tools to encode the text content, font of text watermarks, and the URLs of picture watermarks. The encoded strings of watermarks can be used only in parameters used to add watermarks. Do not include the encoded strings of watermarks in signature strings.

  2. Replace the encoded content based on the following rules:
    • Replace plus signs (+) with hyphens (-).
    • Replace forward slashes (/) with underscores (_).
    • Omit equal signs (=) that are at the end of a string.