Migrate image blind watermark to the new version

Updated at:

The image blind watermark feature of Intelligent Media Management (IMM) allows you to embed invisible text information into an image without affecting its visual quality. You can use the decode blind watermark feature to extract the watermark from the image. This topic describes how to migrate the image blind watermark feature from the old version (API version 2017-09-06) to the new version (API version 2020-09-30).

Background information

Future features and optimizations for image blind watermark will be focused on the new version as the old version is deprecated. The new version offers significant improvements in speed and attack resistance compared to the old version. It is also backward-compatible, allowing it to decode images watermarked by the old version, and supports a wider range of regions. For a better experience, migrate to the new version as soon as possible.

10d1c3ed3dfabf32b4461a50ee2f3f02

Benefits of the new version

  • Attack resistance: The new version provides significantly better attack resistance than the old version. The watermark can still be extracted even after the watermarked image undergoes attacks such as compression, scaling, cropping, or color transformation.

  • Compatibility: The new version can decode image blind watermarks encoded by the old version.

API mapping between the new and old versions

  • SDK/API version

    • The old version uses the old SDK, with API version 2017-09-06.

    • The new version uses the new SDK, with API version 2020-09-30.

The following table describes the API mapping between the new and old versions.

Feature

New API

Old API

Description

Image blind watermark

EncodeBlindWatermark

CreateDecodeBlindWatermarkTask

GetDecodeBlindWatermarkResult

Note

API version: 2020-09-30

EncodeBlindWatermark

DecodeBlindWatermark

Note

API version: 2017-09-06

The new version offers significant improvements in speed and attack resistance. It is also backward-compatible and can decode images watermarked by the old version.

How to migrate

Follow these steps to migrate:

  1. Create a new-version project.

  2. Test the new API operations and switch your services.

  3. Delete the old-version project.

Step 1: Create a new-version project

Note

Before you create a new-version project, check if one already exists. For more information, see Check project version. If a new-version project exists, you do not need to create another one.

Create a new-version project in the console

  1. Log on to the Intelligent Media Management console.

  2. The console provides a switch in the lower-left corner to toggle between the new and old versions. If you are redirected to the old-version console after logging on, click Try New Version in the lower-left corner to switch to the new console.

  3. On the Project List page, select the same region as your old-version project.

    The region selector is located in the top navigation bar, to the right of the Workbench entry.

  4. On the Project List page, click Create Project. In the Create Project panel that appears, enter the project information and create the project.

    Note

    When you create the project, you must select the same service role as the old-version project and set the workflow template to Official:ImageManagement. No other configuration is required.

    The project name must be 1 to 128 characters in length and can contain only letters, digits, hyphens (-), and underscores (_). It must start with a letter or an underscore. The default service role is AliyunIMMDefaultRole.

Step 2: Migrate API calls for adding watermarks

Migrate the API for adding watermarks

Call the new API operation EncodeBlindWatermark.

Important

For the EncodeBlindWatermark operation, set the project_name parameter to the name of your new-version project.

  • SDK/API version

    • The new version uses the new SDK, with API version 2020-09-30.

    • The old version uses the old SDK, with API version 2017-09-06.

  • SDK installation command

    pip install alibabacloud_imm20200930==4.6.1
  • Sample code:

    # -*- 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:
            """
            Initializes a client by using an access key pair.
            @return: Client
            @throws Exception
            """
            # Leaking project code may compromise the security of all resources in your account by exposing your access key.
            # We recommend that you use a more secure method, such as Security Token Service (STS), for authentication.
            config = open_api_models.Config(
                # Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
                access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
                # Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
                access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
            )
            # For more information about endpoints, see https://api.aliyun.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='TestProject',
                source_uri='oss://test/watermark.jpg',
                target_uri='oss://test/target/watermark.jpg',
                content='test'
            )
            runtime = util_models.RuntimeOptions()
            try:
                # When you run the sample code, print the return value of the API operation.
                client.encode_blind_watermark_with_options(encode_blind_watermark_request, runtime)
            except Exception as error:
                # The following code is for demonstration only. We recommend that you handle exceptions with care in your production code.
                # Error message
                print(error.message)
                # Diagnostic URL
                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='TestProject',
                source_uri='oss://test/watermark.jpg',
                target_uri='oss://test/target/watermark.jpg',
                content='test'
            )
            runtime = util_models.RuntimeOptions()
            try:
                # When you run the sample code, print the return value of the API operation.
                await client.encode_blind_watermark_with_options_async(encode_blind_watermark_request, runtime)
            except Exception as error:
                # The following code is for demonstration only. We recommend that you handle exceptions with care in your production code.
                # Error message
                print(error.message)
                # Diagnostic URL
                print(error.data.get("Recommend"))
                UtilClient.assert_as_string(error.message)
    if __name__ == '__main__':
        Sample.main(sys.argv[1:])

Step 3: Migrate API calls for decoding watermarks

Create a watermark decoding task

Call the new API operation CreateDecodeBlindWatermarkTask.

Important

For the CreateDecodeBlindWatermarkTask operation, set the project_name parameter to the name of the new-version project that you created.

  • SDK/API version

    • The new version uses the new SDK, with API version 2020-09-30.

    • The old version uses the old SDK, with API version 2017-09-06.

  • SDK installation command

    pip install alibabacloud_imm20200930==4.6.1
  • Sample code:

    # -*- 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:
            """
            Initializes a client by using an access key pair.
            @return: Client
            @throws Exception
            """
            # Leaking project code may compromise the security of all resources in your account by exposing your access key.
            # We recommend that you use a more secure method, such as Security Token Service (STS). For more information about authentication, see https://help.aliyun.com/document_detail/378659.html.
            config = open_api_models.Config(
                # Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
                access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
                # Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
                access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
            )
            # For more information about endpoints, see https://api.aliyun.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='TestProject',
                source_uri='oss://test/target/watermark.jpg'
            )
            runtime = util_models.RuntimeOptions()
            try:
                # When you run the sample code, print the return value of the API operation.
                client.create_decode_blind_watermark_task_with_options(create_decode_blind_watermark_task_request, runtime)
            except Exception as error:
                # The following code is for demonstration only. We recommend that you handle exceptions with care in your production code.
                # Error message
                print(error.message)
                # Diagnostic URL
                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='TestProject',
                source_uri='oss://test/target/watermark.jpg'
            )
            runtime = util_models.RuntimeOptions()
            try:
                # When you run the sample code, print the return value of the API operation.
                await client.create_decode_blind_watermark_task_with_options_async(create_decode_blind_watermark_task_request, runtime)
            except Exception as error:
                # The following code is for demonstration only. We recommend that you handle exceptions with care in your production code.
                # Error message
                print(error.message)
                # Diagnostic URL
                print(error.data.get("Recommend"))
                UtilClient.assert_as_string(error.message)
    if __name__ == '__main__':
        Sample.main(sys.argv[1:])

Getting the watermark decoding result

Call the new API operation GetDecodeBlindWatermarkResult.

Important

For the GetDecodeBlindWatermarkResult operation, set the project_name parameter to the name of the new-version project that you created.

  • SDK/API version

    • The new version uses the new SDK, with API version 2020-09-30.

  • Sample code:

    # -*- 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:
            """
            Initializes a client by using an access key pair.
            @return: Client
            @throws Exception
            """
            # Leaking project code may compromise the security of all resources in your account by exposing your access key.
            # We recommend that you use a more secure method, such as Security Token Service (STS). For more information about authentication, see https://help.aliyun.com/document_detail/378659.html.
            config = open_api_models.Config(
                # Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
                access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
                # Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
                access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
            )
            # For more information about endpoints, see https://api.aliyun.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()
            get_decode_blind_watermark_result_request = imm_20200930_models.GetDecodeBlindWatermarkResultRequest(
                project_name='TestProject',
                task_type='DecodeBlindWatermark',
                task_id='DecodeBlindWatermark-78ac8f3b-59e0-45a6-9b67-32168c3*****'
            )
            runtime = util_models.RuntimeOptions()
            try:
                # When you run the sample code, print the return value of the API operation.
                client.get_decode_blind_watermark_result_with_options(get_decode_blind_watermark_result_request, runtime)
            except Exception as error:
                # The following code is for demonstration only. We recommend that you handle exceptions with care in your production code.
                # Error message
                print(error.message)
                # Diagnostic URL
                print(error.data.get("Recommend"))
                UtilClient.assert_as_string(error.message)
        @staticmethod
        async def main_async(
            args: List[str],
        ) -> None:
            client = Sample.create_client()
            get_decode_blind_watermark_result_request = imm_20200930_models.GetDecodeBlindWatermarkResultRequest(
                project_name='TestProject',
                task_type='DecodeBlindWatermark',
                task_id='DecodeBlindWatermark-78ac8f3b-59e0-45a6-9b67-32168c3*****'
            )
            runtime = util_models.RuntimeOptions()
            try:
                # When you run the sample code, print the return value of the API operation.
                await client.get_decode_blind_watermark_result_with_options_async(get_decode_blind_watermark_result_request, runtime)
            except Exception as error:
                # The following code is for demonstration only. We recommend that you handle exceptions with care in your production code.
                # Error message
                print(error.message)
                # Diagnostic URL
                print(error.data.get("Recommend"))
                UtilClient.assert_as_string(error.message)
    if __name__ == '__main__':
        Sample.main(sys.argv[1:])

Step 4: Delete the old-version project

Warning

Before you delete the old-version project, ensure that you have fully migrated all services to the new version and that the old project is no longer receiving traffic. This operation is irreversible.

  1. Log on to the Intelligent Media Management console.

  2. In the lower-left corner of the console, click the version switch to return to the old version.

  3. On the Project List page, select the region where your old-version project is located.

    The region selector is in the top navigation bar. For example, select China (Beijing).

  4. On the Project List page, select the old-version project that you want to delete, and then click Delete.

  1. Click OK to confirm the deletion.

Billing for new and old versions

The billable items and billing methods are the same for both the new and old versions.

Image blind watermark billable items

  • For information about billing for the new version of image blind watermark, see Pricing of billable items.

  • For information about billing for the old version of image blind watermark, see Billable Items.

Version

API

Billing

Billing description

Old image blind watermark version

EncodeBlindWatermark

DecodeBlindWatermark

Note

API version: 2017-09-06

Blindwatermark*2

The billable items and billing methods are the same for both versions. The GetDecodeBlindWatermarkResult API operation is not a billable item.

New image blind watermark version

EncodeBlindWatermark

CreateDecodeBlindWatermarkTask

GetDecodeBlindWatermarkResult

Note

API version: 2020-09-30

Blindwatermark*2