You can add text or image watermarks to an image in Object Storage Service (OSS) by using Image Processing (IMG) parameters. This topic describes the parameters that you can use and provides examples on how to use the parameters to add watermarks to an image.
Usage notes
- Only images in the bucket that stores the image you want to watermark can be used as watermarks. To use online or local images as watermarks, you must first upload the images to the bucket.
- Only JPG, PNG, BMP, WebP, and TIFF images can be used as watermarks.
- You can add up to three different image watermarks to a single image, and an image watermark cannot completely overlap with another image watermark.
- Traditional Chinese characters cannot be used as text watermarks.
Parameters
Operation: watermark
The following tables describe the parameters that you can configure when you add watermarks to images.
- Basic parameters
Parameter Required Description Value t No The opacity of the watermark. [0,100] Default value: 100. A value of 100 indicates that the watermark is opaque.
g No The position of the watermark on the image. Default value: se. - nw: upper left.
- north: upper middle.
- ne: upper right.
- west: middle left.
- center: center.
- east: middle right.
- sw: lower left.
- south: lower middle.
- se: lower right.
x No The horizontal margin that specifies the horizontal distance between the watermark and the image edge. This parameter takes effect only when the watermark is on the upper left, middle left, lower left, upper right, middle right, or lower right of the image. [0,4096] Default value: 10
Unit: pixel.
y No The vertical margin that specifies the vertical distance between the watermark and the image edge. This parameter takes effect only when the watermark is on the upper left, upper middle, upper right, lower left, lower middle, or lower right of the image. [0,4096] Default value: 10
Unit: pixel.
voffset No The vertical offset from the middle line. When the watermark is in the middle left, center, or middle right of the image, you can specify the vertical offset of the watermark along the middle line. [-1000,1000] Default value: 0.
Unit: pixel.
fill No Specifies whether to tile the image watermarks or text watermarks across the image. Default value: 0. Note If you want to add tiled watermarks, submit an application at Quota Center..- 1: tiles the image watermarks or text watermarks across the image.
- 0: does not tile the image watermarks or text watermarks across the image.
padx No The horizontal spacing between watermarks when the source image is filled with the image watermarks or text watermarks. This parameter is valid only when you set fill to 1. [0,4096] Default value: 0.
Unit: pixel.
pady No The vertical spacing between watermarks when the source image is filled with the image watermarks or text watermarks. This parameter is valid only when you set fill to 1. [0,4096] Default value: 0.
Unit: pixel.
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 contains multiple watermarks.
The following figure shows the positions of watermarks based on coordinates. - Image watermark parameters
Parameter Required Description Value image Yes The complete name of the image object that you want to use as a watermark. The object name must be Base64-encoded. For more information, see Encode watermarks. For example, if you want to use an image object named panda.png in the image directory of the current bucket as a watermark, the object name to encode is image/panda.png and the encoded object name is
aW1hZ2UvcGFuZGEucG5n
.Note Only objects in the current bucket can be used as watermarks.Base64-encoded strings. - Parameters for watermark image preprocessing
You can preprocess a watermark image by performing the Resize images, Custom crop, Indexed slice, Rounded rectangle, and Rotate operations. In addition, the P parameter is supported when you resize a watermark image.
Parameter Description Value P The size of the watermark image relative to the source image. The value of this parameter specifies the size of the watermark in percentage of the source image size. For example, if you set this parameter to 10 for a source image of 100 × 100 pixels, the size of the watermark image is 10 × 10 pixels. If the size of the source image is 200 × 200 pixels, the size of the watermark image is 20 × 20 pixels. [1,100] - Text watermark parameters
Parameter Required Description Value text Yes The content of the text watermark. The text content must be Base64-encoded. For more information, see Encode watermarks. A Chinese string cannot exceed 64 characters in length before the string is Base64-encoded. type No The font of the text watermark. The font name must be Base64-encoded. For more information about the supported fonts and the encoded strings for the fonts, see Font types and encoded strings. Default value: wqy-zenhei (encoded value: d3F5LXplbmhlaQ).
color No 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: 000000.
size No The size of the text watermark. (0,1000] Default value: 40.
Unit: pixel.
shadow No The opacity of the shadow for the text watermark. [0,100] Default value: 0. A value of 0 specifies no shadows are added to the text.
rotate No The degree by which the text is rotated clockwise. [0,360] Default value: 0. A value of 0 specifies that the text is not rotated.
The following table describes the valid values of the type parameter and the encoded strings of these values.
Description Font name Encoded value wqy-zenhei WenQuanYi Zen Hei d3F5LXplbmhlaQ wqy-microhei WenQuanYi Micro Hei d3F5LW1pY3JvaGVp fangzhengshusong Fangzheng Shusong ZmFuZ3poZW5nc2h1c29uZw fangzhengkaiti Fangzheng Kaiti ZmFuZ3poZW5na2FpdGk fangzhengheiti Fangzheng Heiti ZmFuZ3poZW5naGVpdGk fangzhengfangsong Fangzheng Fangsong ZmFuZ3poZW5nZmFuZ3Nvbmc droidsansfallback DroidSansFallback ZHJvaWRzYW5zZmFsbGJhY2s - Text-and-image watermark parameters
Parameter Required Description Value order No The order of the text watermark and image watermark. 0 and 1. Default value: 0. - 0: The image watermark is on the top of the text watermark.
- 1: The text watermark is on the top of the image watermark.
align No The alignment of the text watermark and image watermark. 0, 1, and 2. Default value: 2. - 0: The text watermark and the image watermark are aligned based on top alignment.
- 1: The text watermark and the image watermark are aligned based on center alignment.
- 2: The text watermark and the image watermark are aligned based on bottom alignment.
interval No The spacing between the text watermark and image watermark. [0,1000] Default value: 0.
Unit: pixel.
Encode watermarks
The content, color, and font of a text watermark and the name of an image watermark must be a URL-safe string that is Base64-encoded. Perform the following steps to encode watermarks:
- Encode the content by using Base64.
- Replace the following characters in the encoded string:
- Replace the plus signs (+) in the encoded string with hyphens (-).
- Replace the forward slashes (/) in the encoded string with underscores (_).
- Omit the equal signs (=) at the end of the encoded string.
We recommend that you use base64url encoder to encode the content, color, and font of a text watermark and the name of an image watermark.
Example 1: Add a text watermark to an image
You can use object URLs, OSS SDKs, or API operations to configure IMG parameters that are used to process images. In this example, object URLs are used. You can use object URLs to configure IMG parameters only for public-read images. If you want to configure IMG parameters for private images, use OSS SDKs or API operations. For more information, see IMG implementation modes.

The following examples show how to add a text watermark to example.jpg:
- Add the string "Hello World" to the image as a text watermarkBase64-encode the string "Hello World" into a URL-safe string. For more information, see Encode watermarks. The encoded result is
SGVsbG8gV29ybGQ
and the URL used to process the image is https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/watermark,text_SGVsbG8gV29ybGQ. - Configure multiple IMG parameters when you add a text watermark to the image
In this example, IMG parameters are configured to perform the following operations on the source image and text watermark "Hello World" that you want to add to the source image:
- Resize the source image example.jpg to 300 × 300 pixels by using
resize,w_300,h_300
. - Set the font of the text watermark to WenQuanYi Zen Hei by using
type_d3F5LXplbmhlaQ
. d3F5LXplbmhlaQ is the Base64-encoded value of WenQuanYi Zen Hei. - Add the string "Hello World" to the source image as a text watermark by using
text_SGVsbG8gV29ybGQ
. - Set the color of the text watermark to white and the size of the text to 30 pixels by using
color_FFFFFF,size_30
. - Set the opacity of the shadow of the text watermark to 50% by using
shadow_50
. - 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 using
g_se,x_10,y_10
.
- Resize the source image example.jpg to 300 × 300 pixels by using
Example 2: Add an image watermark to the source image
The following examples show how to add an image watermark to the example.jpg image:
- Add the panda.png image to the source image as an image watermarkBase64-encode the name of the panda.png image into a URL-safe string. The encoded result is
cGFuZGEucG5n
and the URL used to process the image is https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/watermark,image_cGFuZGEucG5n. - Configure multiple IMG parameters when you add an image watermark to the source image
In this example, IMG parameters are configured to perform the following operations on the source image and the panda.png image that you want to add to the source image as an image watermark:
- Resize the source image example.jpg to 300 × 300 pixels by using
resize,w_300,h_300
. - Set the quality of the source image example.jpg to 90% by using
quality,q_90
. - Add the image watermark panda.png by using
watermark,image_cGFuZGEucG5n
. cGFuZGEucG5n is the Base64-encoded value of panda.png. - Set the opacity of the image watermark to 90% by using
t_90
. - Set the position of the image watermark to lower right, the horizontal margin to 10 pixels, and the vertical offset from the middle line to 10 pixels by using
g_se,x_10,y_10
.
The following URL is used to apply the preceding parameters: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,w_300,h_300/quality,q_90/watermark,image_cGFuZGEucG5n,t_90,g_se,x_10,y_10. - Resize the source image example.jpg to 300 × 300 pixels by using
- Preprocess the image watermark and then configure IMG parameters
In this example, IMG parameters are configured to perform the following operations on the source image and the panda.png image that you want to add to the source image as an image watermark:
- Resize the width of the source image example.jpg to 300 pixels by using
resize,w_300
. - Resize the image watermark panda.png to 30% of the original size by using
image_cGFuZGEucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2UvcmVzaXplLFBfMzA
.cGFuZGEucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2UvcmVzaXplLFBfMzA
is the Base64-encoded value ofpanda.png?x-oss-process=image/resize,P_30
. - Set the opacity of the image watermark to 90%, the position of the image watermark to lower right, the horizontal margin to 10 pixels, and the vertical offset from the middle line to 10 pixels by using
t_90,g_se,x_10,y_10
.
- Resize the width of the source image example.jpg to 300 pixels by using
- Add multiple image watermarks to the source image
Add image watermarks panda.png and Tulips.jpg. to the example.jpg image
- Base64-encode the name of the panda.png image into a URL-safe string. The encoded result is
cGFuZGEucG5n
. Add the panda.png image as an image watermark by usingwatermark,image_cGFuZGEucG5n
. - Base64-encode the name of the Tulips.jpg image into a URL-safe string. The encoded result is
VHVsaXBzLmpwZw
. Place the image watermark on the middle left of the source image, set the horizontal margin to 10 pixels, and set the vertical offset from the middle line to 10 pixels by usingwatermark,image_VHVsaXBzLmpwZw,g_west,x_10,y_10
.
The following URL is used to apply the preceding parameters:
https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/watermark,image_cGFuZGEucG5n/watermark,image_VHVsaXBzLmpwZw,g_west,x_10,y_10 - Base64-encode the name of the panda.png image into a URL-safe string. The encoded result is
Example 3: Add text and image watermarks to the source image
The following example shows how to add text and image watermarks to the example.jpg image:

FAQ
How do I use online or local images as watermark images?
When IMG is used to add image watermarks to a source image, make sure that the watermark images and the source image are stored in the same bucket. To add online or local images to a source image as image watermarks, you must first upload the images to the bucket in which the source image is stored.
What do I do if the "font content is too large" message appears when I add a text watermark?
When you add a text watermark to an image by using OSS IMG parameters, the maximum length of a text watermark cannot exceed 64 characters (One Chinese character is treated as three characters). When the "font content is too large" message appears, we recommend that you shorten the text watermark. For more information, see Example 1: Add a text watermark to an image.
What do I do if I fail to add an image watermark to a private object?
The URL of a private object is signed. IMG parameters cannot be added to a signed URL. If you want to process a private object, add IMG parameters to the signature. For more information, see Generate a signed URL that includes IMG parameters for an object.
Can I add a background color to an image watermark when I add the image watermark?
No, you cannot add a background color to an image watermark.
How do I use a signed URL to access an image?
The URL of a private object must be signed. IMG parameters cannot be added to a signed URL. If you want to process a private object, add IMG parameters to the signature. For more information, see IMG.