Blind watermarking is a watermarking technique that allows you to embed imperceptible text information into images. A blind watermark can be extracted even if the watermarked image is processed by common image processing operations, such as compression, resizing, cropping, and color changing.
How it works
The following figure shows the process of blind watermarking.

Limits
Only blind text watermarks are supported. A blind text watermark can be up to 256 characters in length.
You can add blind watermarks only to JPG, PNG, BMP, TIFF, and WebP images. The minimum image width and height are 80 pixels. The maximum image width and height are 10,000 pixels.
Blind watermarks are robust against common processing operations and attacks, such as screenshot, cropping, JPEG compression, resizing, color changing, saturation adjustment, hue adjustment, brightness adjustment, and addition of lightweight graffiti.
Blind watermarking does not support pure-white, pure-black images, or images with a too low resolution, for example, less than 200 × 200 pixels. The ratio of the short edge to the long edge must be greater than 1:2.
Scenarios
Proof of ownership and legal evidence: Blind watermarks can be used to prove ownership in case of ownership disputes.
Image deduplication for uploads: You can use blind watermarks to detect whether an image to upload already exists in the resource library.
Resource leak prevention: If images are distributed illegally, blind watermarks can be used to trace the source of the leak, which helps prevent resource leaks.
Prerequisites
An AccessKey pair is created and obtained. For more information, see Create an AccessKey pair.
The relevant objects are uploaded to an OSS bucket. For more information, see Upload objects.
Intelligent Media Management (IMM) is activated. For more information, see Activate IMM.
A project is created in the IMM console. For more information, see Create a project.
You can also call the CreateProject operation to create a project. For more information, see CreateProject.
You can call the ListProjects operation to list all projects in the specified region.
Usage
Add a blind watermark
Call the EncodeBlindWatermark operation to add a blind watermark to an image.
Image information
IMM project: test-project
Image address: oss://test-bucket/test-object.jpg
Image:

Sample request
{
"ProjectName": "test-project",
"SourceURI": "oss://test-bucket/test-object.jpg",
"TargetURI": "oss://test-bucket/blindwatermark-object.jpg",
"Content": "All rights reserved by Alibaba Cloud",
}Sample response
{
"RequestId": "4FACCDBE-6D15-4E02-9924-1CC5FAF2A9B3",
}Sample code
The following sample code provides an example on how to add a blind watermark to an image by using IMM SDK for Python:
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import os
import sys
from typing import List
from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> imm20200930Client:
"""
Use the AccessKey ID and AccessKey secret to initialize the client.
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
# If the project code is leaked, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. The following lines are provided for reference only.
# For security reasons, we recommend that you use temporary access credentials that are provided by Security Token Service (STS). For more information, visit https://www.alibabacloud.com/help/en/sdk/developer-reference/v2-manage-php-access-credentials.
config = open_api_models.Config(
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. ,
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. ,
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
# Specify the IMM endpoint. For a list of IMM endpoints for supported regions, visit https://api.alibabacloud.com/product/imm.
config.endpoint = f'imm.cn-hangzhou.aliyuncs.com'
return imm20200930Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
encode_blind_watermark_request = imm_20200930_models.EncodeBlindWatermarkRequest(
project_name='test-project',
source_uri='oss://test-bucket/test-object.jpg',
target_uri='oss://test-bucket/blindwatermark-object.jpg',
content='All rights reserved by Alibaba Cloud'
)
runtime = util_models.RuntimeOptions()
try:
# Print the response of the API operation if necessary.
client.encode_blind_watermark_with_options(encode_blind_watermark_request, runtime)
except Exception as error:
# Handle exceptions with caution in your actual business scenario and never ignore exceptions in your project. In this example, error messages are printed to the screen.
# Display error messages.
print(error.message)
# Show the URL for troubleshooting.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
encode_blind_watermark_request = imm_20200930_models.EncodeBlindWatermarkRequest(
project_name='test-project',
source_uri='oss://test-bucket/test-object.jpg',
target_uri='oss://test-bucket/blindwatermark-object.jpg',
content='All rights reserved by Alibaba Cloud'
)
runtime = util_models.RuntimeOptions()
try:
# Print the response of the API operation if necessary.
await client.encode_blind_watermark_with_options_async(encode_blind_watermark_request, runtime)
except Exception as error:
# Handle exceptions with caution in your actual business scenario and never ignore exceptions in your project. In this example, error messages are printed to the screen.
# Display error messages.
print(error.message)
# Show the URL for troubleshooting.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
Decode a blind watermark
Call the CreateDecodeBlindWatermarkTask operation to decode the blind watermark in an image. After the watermark decoding task is complete, you can obtain the blind watermark by calling the GetDecodeBlindWatermarkResult operation or from the asynchronous notification.
The task information is retained for seven days after the task starts. Task information cannot be obtained after the seven-day window ends. You can use one of the following methods to query task information:
In the region in which the IMM project is located, configure a Simple Message Queue (SMQ) subscription to receive task information notifications. For information about the asynchronous notification format, see Asynchronous message examples. For more information about SMQ SDKs, see Step 4: Receive and delete the message.
In the region in which the IMM project is located, create an ApsaraMQ for RocketMQ 4.0 instance, a topic, and a group to receive task notifications. For more information about the asynchronous notification format, see Asynchronous message examples. For more information about how to use ApsaraMQ for RocketMQ, see Use HTTP client SDKs to send and subscribe to normal messages.
In the region in which the IMM project is located, use EventBridge to receive task information notifications. For more information, see IMM events.
Image information
IMM project: test-project
Image location: oss://test-bucket/blindwatermark-object.jpg
Image:

Sample request
{
"ProjectName": "test-project",
"SourceURI": "oss://test-bucket/blindwatermark-object.jpg",
}Sample response
{
"TaskId": "DecodeBlindWatermark-23dee5ea-d890-4f82-9357-fa6ad027b2a9",
"RequestId": "79DD63F2-B72D-0E53-97AA-8B98C1758DBF",
"EventId": "073-1oOm1dJjEUrCnQz0oFqtEwO7rJr"
}Sample code
The following sample code provides an example on how to decode a blind watermark by using IMM SDK for Python:
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import os
import sys
from typing import List
from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> imm20200930Client:
"""
Use the AccessKey ID and AccessKey secret to initialize the client.
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
# If the project code is leaked, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. The following lines are provided for reference only.
# For security reasons, we recommend that you use temporary access credentials that are provided by Security Token Service (STS). For more information, visit https://www.alibabacloud.com/help/en/sdk/developer-reference/v2-manage-php-access-credentials.
config = open_api_models.Config(
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. ,
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. ,
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
# Specify the IMM endpoint. For a list of IMM endpoints for supported regions, visit https://api.alibabacloud.com/product/imm.
config.endpoint = f'imm.cn-hangzhou.aliyuncs.com'
return imm20200930Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
create_decode_blind_watermark_task_request = imm_20200930_models.CreateDecodeBlindWatermarkTaskRequest(
project_name='test-project',
source_uri='oss://test-bucket/blindwatermark-object.jpg'
)
runtime = util_models.RuntimeOptions()
try:
# Print the response of the API operation if necessary.
client.create_decode_blind_watermark_task_with_options(create_decode_blind_watermark_task_request, runtime)
except Exception as error:
# Handle exceptions with caution in your actual business scenario and never ignore exceptions in your project. In this example, error messages are printed to the screen.
# Display error messages.
print(error.message)
# Show the URL for troubleshooting.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
create_decode_blind_watermark_task_request = imm_20200930_models.CreateDecodeBlindWatermarkTaskRequest(
project_name='test-project',
source_uri='oss://test-bucket/blindwatermark-object.jpg'
)
runtime = util_models.RuntimeOptions()
try:
# Print the response of the API operation if necessary.
await client.create_decode_blind_watermark_task_with_options_async(create_decode_blind_watermark_task_request, runtime)
except Exception as error:
# Handle exceptions with caution in your actual business scenario and never ignore exceptions in your project. In this example, error messages are printed to the screen.
# Display error messages.
print(error.message)
# Show the URL for troubleshooting.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])