All Products
Search
Document Center

Watermark

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Add a watermark

For more information about the request and response parameters, see AddWatermark.

/**
 * Method for constructing the configuration of an image watermark. Modify parameters as required.
 * @return
 */
function buildImageWatermarkConfig() {
    $watermarkConfig = array();
    // The lateral offset of the watermark.
    $watermarkConfig["Dx"] = "8";
    // The longitudinal offset of the watermark.
    $watermarkConfig["Dy"] = "8";
    // The width of the watermark.
    $watermarkConfig["Width"] = "55";
    // The height of the watermark.
    $watermarkConfig["Height"] = "55";
    // The relative display position of the watermark, such as the top-left, top-right, bottom-left, or bottom-right corner.
    $watermarkConfig["ReferPos"] = "BottomRight";

    // The timeline of watermark display, including the start time and end time.
    $timeline = array();
    // The start time for watermark display.
    $timeline["Start"] = "2";
    // The end time for watermark display.
    $timeline["Duration"] = "ToEND";
    $watermarkConfig["Timeline"] = $timeline;

    return json_encode($watermarkConfig);
}

/**
 * Method for constructing the configuration of a text watermark. Modify parameters as required.
 * @return
 */
function buildTextWatermarkConfig() {
    $watermarkConfig = array();
    // The content of the text watermark.
    $watermarkConfig["Content"] = "testwatermark";
    // The font of the text watermark.
    $watermarkConfig["FontName"] = "SimSun";
    // The font size of the text watermark.
    $watermarkConfig["FontSize"] = "25";
    // The color or RGB value (such as #000000) of the text watermark.
    $watermarkConfig["FontColor"] = "Black";
    // The transparency of the text watermark.
    $watermarkConfig["FontAlpha"] = "0.2";
    // The color or RGB value (such as #ffffff) of the font outline for the text watermark.
    $watermarkConfig["BorderColor"] = "White";
    // The outline width of the text watermark.
    $watermarkConfig["BorderWidth"] = "1";
    // The offset of the text watermark to the top of the video image.
    $watermarkConfig["Top"] = "20";
    // The offset of the text watermark to the left of the video image.
    $watermarkConfig["Left"] = "15";

    return json_encode($watermarkConfig);
}

/**
 * Method for adding the watermark configuration
 */
function addWatermark($client) {
    $request = new vod\AddWatermarkRequest();
    // Sets the watermark name.
    $request->setName("addwatermark");

    // Obtains the OSS URL of the watermark file.
    // The OSS URL must be specified for an image watermark file. This watermark file must be stored in the same region as the relevant video. For example, if a video is stored in China (Shanghai), its watermark file must also be stored in China (Shanghai).
    $request->setFileUrl("http://test-bucket.oss-cn-shanghai.aliyuncs.com/watermark/test.png");

    // Specifies the watermark configuration.
    // Specifies the display position configuration of an image watermark.
    $request->setWatermarkConfig(buildImageWatermarkConfig());
    // Specifies the display position configuration of a text watermark.
    //$request->setWatermarkConfig(buildTextWatermarkConfig());

    // Sets the watermark type. Enter Text for a text watermark or Image for an image watermark.
    $request->setType("Image");

    return $client->getAcsResponse($request);
}

/**
 * Call example
 * @param args
 */
try {
    $client = initVodClient("<AccessKeyId>", "<AccessKeySecret>"); 

    $result = addWatermark($client);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n"; 
}

Modify a watermark

For more information about the request and response parameters, see UpdateWatermark.

/**
 * Method for constructing the configuration of an image watermark. Modify parameters as required.
 * @return
 */
function buildImageWatermarkConfig() {
    $watermarkConfig = array();
    // The lateral offset of the watermark.
    $watermarkConfig["Dx"] = "10";
    // The longitudinal offset of the watermark.
    $watermarkConfig["Dy"] = "10";
    // The width of the watermark.
    $watermarkConfig["Width"] = "66";
    // The height of the watermark.
    $watermarkConfig["Height"] = "66";
    // The relative display position of the watermark, such as the top-left, top-right, bottom-left, or bottom-right corner.
    $watermarkConfig["ReferPos"] = "BottomRight";

    // The timeline of watermark display, including the start time and end time.
    $timeline = array();
    // The start time for watermark display.
    $timeline["Start"] = "2";
    // The end time for watermark display.
    $timeline["Duration"] = "ToEND";
    $watermarkConfig["Timeline"] = $timeline;

    return json_encode($watermarkConfig);
}

/**
 * Method for constructing the configuration of a text watermark. Modify parameters as required.
 * @return
 */
function buildTextWatermarkConfig() {
    $watermarkConfig = array();
    // The content of the text watermark.
    $watermarkConfig["Content"] = "testwatermark";
    // The font of the text watermark.
    $watermarkConfig["FontName"] = "SimSun";
    // The font size of the text watermark.
    $watermarkConfig["FontSize"] = "40";
    // The color or RGB value (such as #000000) of the text watermark.
    $watermarkConfig["FontColor"] = "Black";
    // The transparency of the text watermark.
    $watermarkConfig["FontAlpha"] = "0.2";
    // The color or RGB value (such as #ffffff) of the font outline for the text watermark.
    $watermarkConfig["BorderColor"] = "White";
    // The outline width of the text watermark.
    $watermarkConfig["BorderWidth"] = "2";
    // The offset of the text watermark to the top of the video image.
    $watermarkConfig["Top"] = "20";
    // The offset of the text watermark to the left of the video image.
    $watermarkConfig["Left"] = "15";

    return json_encode($watermarkConfig);
}

/**
 * Call example
 * @param args
 */
try {
    $client = initVodClient("<AccessKeyId>", "<AccessKeySecret>");

    $result = updateWatermark($client);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n"; 
}

Delete a watermark

For more information about the request and response parameters, see DeleteWatermark.

/**
 * Method for deleting the watermark configuration
 */
function deleteWatermark($client) {
    $request = new vod\DeleteWatermarkRequest();
    // Sets the watermark ID.
    $request->setWatermarkId("e7d983370268092176588a2c4xxxxxx");

    return $client->getAcsResponse($request);
}

/**
 * Call example
 * @param args
 */
try {
    $client = initVodClient("<AccessKeyId>", "<AccessKeySecret>"); 

    $result = deleteWatermark($client);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n"; 
}

Query a list of watermarks

For more information about the request and response parameters, see ListWatermark.

/**
 * Method for querying the configuration of watermarks
 */
function listWatermark($client) {
    $request = new vod\ListWatermarkRequest();
    return $client->getAcsResponse($request);
}

/**
 * Call example
 * @param args
 */
try {
    $client = initVodClient("<AccessKeyId>", "<AccessKeySecret>"); 

    $result = listWatermark($client);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n"; 
}

Query a watermark

For more information about the request and response parameters, see GetWatermark.

/**
 * Method for querying the configuration of a watermark
 */
function getWatermark($client) {
    $request = new vod\GetWatermarkRequest();
    // Specifies the ID of the watermark to be queried.
    $request->setWatermarkId("bfc084674fb64486b6e5bace30xxxxxx");

    return $client->getAcsResponse($request);
}

/**
 * Call example
 * @param args
 */
try {
    $client = initVodClient("<AccessKeyId>", "<AccessKeySecret>"); 

    $result = getWatermark($client);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n"; 
}

Set the default watermark

For more information about the request and response parameters, see SetDefaultWatermark.

/**
 * Method for setting the default watermark configuration
 */
function setDefaultWatermark($client) {
    $request = new vod\SetDefaultWatermarkRequest();
    // Sets the ID of the default watermark.
    $request->setWatermarkId("bfc084674fb64486b6e5bace30xxxxxx");

    return $client->getAcsResponse($request);
}

/**
 * Call example
 * @param args
 */
try {
    $client = initVodClient("<AccessKeyId>", "<AccessKeySecret>"); 

    $result = setDefaultWatermark($client);
    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n"; 
}