This topic provides examples on how to call the API operations that are encapsulated in ApsaraVideo Media Processing (MPS) SDK for PHP to manage watermark templates.

Prerequisites

MPS SDK for PHP is installed and configured. For more information, see Overview. To obtain more information about the SDK and view examples on how to use the SDK to call API operations, visit OpenAPI Explorer.

Create a watermark template

Call the AddWaterMarkTemplate operation to create a watermark template. For more information about the request and response parameters, see AddWaterMarkTemplate. Sample request:

<?php

// This file is auto-generated, don't edit it. Thanks.
namespace AlibabaCloud\SDK\Sample;

use AlibabaCloud\SDK\Mts\V20140618\Mts;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\AddWaterMarkTemplateRequest;

class Sample {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize the client.
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Mts Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        $config = new Config([
            // Your AccessKey ID.
            "accessKeyId" => $accessKeyId,
            // Your AccessKey secret.
            "accessKeySecret" => $accessKeySecret
        ]);
        // The endpoint.
        $config->endpoint = "mts.cn-shanghai.aliyuncs.com";
        return new Mts($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient("accessKeyId", "accessKeySecret");
        $addWaterMarkTemplateRequest = new AddWaterMarkTemplateRequest([
            // The configuration of the watermark template. The Type field indicates the watermark type and must be set to Image. 
            "config" => "{\"Width\":\"10\",\"Height\":\"30\",\"Dx\":\"10\",\"Dy\":\"5\",\"ReferPos\":\"TopRight\",\"Type\":\"Image\",\"Timeline\":{\"Start\":\"0\",\"Duration\":\"10\"}}",
            // The name of the watermark template. The name can contain letters and digits and can be up to 128 bytes in size. 
            "name" => "example-watermark"
        ]);
        $client->addWaterMarkTemplate($addWaterMarkTemplateRequest);
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
Sample::main(array_slice($argv, 1));

Update a watermark template

Call the UpdateWaterMarkTemplate operation to update a watermark template. For more information about the request and response parameters, see UpdateWaterMarkTemplate. Sample request:

<?php

// This file is auto-generated, don't edit it. Thanks.
namespace AlibabaCloud\SDK\Sample;

use AlibabaCloud\SDK\Mts\V20140618\Mts;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\UpdateWaterMarkTemplateRequest;

class Sample {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize the client.
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Mts Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        $config = new Config([
            // Your AccessKey ID.
            "accessKeyId" => $accessKeyId,
            // Your AccessKey secret.
            "accessKeySecret" => $accessKeySecret
        ]);
        // The endpoint.
        $config->endpoint = "mts.cn-shanghai.aliyuncs.com";
        return new Mts($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient("accessKeyId", "accessKeySecret");
        $updateWaterMarkTemplateRequest = new UpdateWaterMarkTemplateRequest([
            // The ID of the watermark template to be updated.
            "waterMarkTemplateId" => "94ac199566d6414f9110a3b37e8c****",
            // The new name of the watermark template. The name can contain letters and digits and can be up to 128 bytes in size.
            "name" => "WaterMark-example",
            // The updated configuration of the watermark template.
            "config" => "{\"Width\":\"10px\",\"Height\":\"30px\",\"Dx\":\"10px\",\"Dy\":\"5px\",\"Type\":\"Image\",\"Timeline\":{\"Start\":\"0\",\"Duration\":\"10\"}}"
        ]);
        $client->updateWaterMarkTemplate($updateWaterMarkTemplateRequest);
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
Sample::main(array_slice($argv, 1));

Query one or more watermark templates

Call the QueryWaterMarkTemplateList operation to query one or more watermark templates. For more information about the request and response parameters, see QueryWaterMarkTemplateList. Sample request:

<?php

// This file is auto-generated, don't edit it. Thanks.
namespace AlibabaCloud\SDK\Sample;

use AlibabaCloud\SDK\Mts\V20140618\Mts;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\QueryWaterMarkTemplateListRequest;

class Sample {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize the client.
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Mts Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        $config = new Config([
            // Your AccessKey ID.
            "accessKeyId" => $accessKeyId,
            // Your AccessKey secret.
            "accessKeySecret" => $accessKeySecret
        ]);
        // The endpoint.
        $config->endpoint = "mts.cn-shanghai.aliyuncs.com";
        return new Mts($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient("accessKeyId", "accessKeySecret");
        $queryWaterMarkTemplateListRequest = new QueryWaterMarkTemplateListRequest([
            // The ID of the watermark template to be queried. You can query up to 10 watermark templates at a time. Separate multiple IDs with commas (,).
            "waterMarkTemplateIds" => "94ac199566d6414f9110a3b37e8c****"
        ]);
        $client->queryWaterMarkTemplateList($queryWaterMarkTemplateListRequest);
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
Sample::main(array_slice($argv, 1));

Search for watermark templates in the specified state

Call the SearchWaterMarkTemplate operation to search for watermark templates in the specified state. For more information about the request and response parameters, see SearchWaterMarkTemplate. Sample request:

<?php

// This file is auto-generated, don't edit it. Thanks.
namespace AlibabaCloud\SDK\Sample;

use AlibabaCloud\SDK\Mts\V20140618\Mts;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\SearchWaterMarkTemplateRequest;

class Sample {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize the client.
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Mts Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        $config = new Config([
            // Your AccessKey ID.
            "accessKeyId" => $accessKeyId,
            // Your AccessKey secret.
            "accessKeySecret" => $accessKeySecret
        ]);
        // The endpoint.
        $config->endpoint = "mts.cn-shanghai.aliyuncs.com";
        return new Mts($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient("accessKeyId", "accessKeySecret");
        $searchWaterMarkTemplateRequest = new SearchWaterMarkTemplateRequest([
            // The state of the watermark templates that you search for.
            "state" => "Normal",
            // The number of entries to return on each page.
            "pageSize" => 10,
            // The number of the current page.
            "pageNumber" => 1
        ]);
        $client->searchWaterMarkTemplate($searchWaterMarkTemplateRequest);
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
Sample::main(array_slice($argv, 1));

Delete a watermark template

Call the DeleteWaterMarkTemplate operation to delete a watermark template. For more information about the request and response parameters, see DeleteWaterMarkTemplate. Sample request:

<?php

// This file is auto-generated, don't edit it. Thanks.
namespace AlibabaCloud\SDK\Sample;

use AlibabaCloud\SDK\Mts\V20140618\Mts;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\DeleteWaterMarkTemplateRequest;

class Sample {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize the client.
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Mts Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        $config = new Config([
            // Your AccessKey ID.
            "accessKeyId" => $accessKeyId,
            // Your AccessKey secret.
            "accessKeySecret" => $accessKeySecret
        ]);
        // The endpoint.
        $config->endpoint = "mts.cn-shanghai.aliyuncs.com";
        return new Mts($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient("accessKeyId", "accessKeySecret");
        $deleteWaterMarkTemplateRequest = new DeleteWaterMarkTemplateRequest([
            // The ID of the watermark template to be deleted.
            "waterMarkTemplateId" => "98a5f54d54a741edb047e337ad86****"
        ]);
        $client->deleteWaterMarkTemplate($deleteWaterMarkTemplateRequest);
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
Sample::main(array_slice($argv, 1));