Image watermarks

更新时间:
复制 MD 格式

Image watermarking adds an image as a layer on top of an original image to identify the image or protect its copyright.

Access type

@watermark=1&object=<encodedobject>&t=<transparency>&x=<distanceX>&y=<distanceY>&p=<position>…

The watermark and object parameters are required. In this document, `url_safe_base64_encode` refers to URL-safe Base64 encoding. For more information, see Keywords.

Parameters

Name

Description

Parameter type

object

The name of the watermark image object. The name must be URL-safe Base64 encoded: encodedObject = url_safe_base64_encode(object).

Note

For example, if the object is "panda.png", the encoded content is "cGFuZGEucG5n".

Required

For information about watermark position parameters, see Basic parameters.

Watermark image pre-processing

You can pre-process a watermark image before you add it. Supported operations include scaling, cropping, and rotation. Inscribed circle cropping or pipeline operations are not supported. For more information about these operations, see the relevant sections of this document. You can also use the `P` parameter, with a value from 1 to 100, to scale the watermark image as a percentage of the main image's size.

Pre-processing example

For example, if you set the `P` parameter to 10, a 100 × 100 main image will have a 10 × 10 watermark. Similarly, a 200 × 200 main image will have a 20 × 20 watermark. The `P` parameter dynamically adjusts the watermark size based on the size of the main image.

Example of a watermark operation: watermark=1&object=cGFuZGEucG5nQDMwUA&t=90&p=9&x=10&y=10. This operation adds a watermark to the lower-right corner. The watermark image is `panda.png@30P`, which means the watermark is scaled to 30% of the main image's size.

Scale the original image to a width of 400 pixels, then add the watermark:

https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/example.jpg@400w|watermark=1&object=cGFuZGEucG5nQDMwUA&t=90&p=9&x=10&y=10

Image watermark 1

Request format

The `object` parameter must be in the following format: `Original image name (unencoded) + @ + Action`. The entire string must then be URL-safe Base64 encoded.

Examples:

  • No pre-processing: object = url_safe_base64_encode("panda.png")

  • Scale to 200%: object = url_safe_base64_encode("panda.png@200p")

  • Scale to 50%, brightness 50, contrast 40: object = url_safe_base64_encode("panda.png@50p_50b_40d")

  • Scale to a width of 50, brightness 30: object = url_safe_base64_encode("panda.png@50w_30b")

  • Scale to a height of 20, contrast 10: object = url_safe_base64_encode("panda.png@20h_10d")

  • Scale to 20% of the original image size, contrast 10: object = url_safe_base64_encode("panda.png@20P_10d")

Examples