updateMediaWatermarkTemplate.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. require dirname(__FILE__, 2) . '/vendor/autoload.php';
  3. $secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
  4. $secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
  5. $region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
  6. $cosClient = new Qcloud\Cos\Client(
  7. array(
  8. 'region' => $region,
  9. 'scheme' => 'https', //协议头部,默认为http
  10. 'credentials'=> array(
  11. 'secretId' => $secretId,
  12. 'secretKey' => $secretKey)));
  13. try {
  14. // https://cloud.tencent.com/document/product/436/54036 更新水印模板
  15. // 文本
  16. $result = $cosClient->updateMediaWatermarkTemplate(array(
  17. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  18. 'Key' => '', // TemplateId
  19. 'Tag' => 'Watermark',
  20. 'Name' => 'Watermark-Template-Name',
  21. 'Watermark' => array(
  22. 'Type' => 'Text',
  23. 'Pos' => 'TopRight',
  24. 'LocMode' => 'Absolute',
  25. 'Dx' => '128',
  26. 'Dy' => '128',
  27. 'StartTime' => '',
  28. 'EndTime' => '',
  29. 'Text' => array(
  30. 'FontSize' => '30',
  31. 'FontType' => 'simfang',
  32. 'FontColor' => '0x000000',
  33. 'Transparency' => '30',
  34. 'Text' => '水印内容',
  35. ),
  36. ),
  37. ));
  38. // 请求成功
  39. print_r($result);
  40. // 图片
  41. $result = $cosClient->updateMediaWatermarkTemplate(array(
  42. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  43. 'Key' => '', // TemplateId
  44. 'Tag' => 'Watermark',
  45. 'Name' => 'Watermark-Template-Name2-1',
  46. 'Watermark' => array(
  47. 'Type' => 'Image',
  48. 'Pos' => 'TopRight',
  49. 'LocMode' => 'Absolute',
  50. 'Dx' => '128',
  51. 'Dy' => '128',
  52. 'StartTime' => '',
  53. 'EndTime' => '',
  54. 'Image' => array(
  55. 'Url' => 'https://examplebucket-125000000.cos.ap-guangzhou.myqcloud.com/test01.png',
  56. 'Mode' => 'Proportion',
  57. 'Width' => '10',
  58. 'Height' => '',
  59. 'Transparency' => '100',
  60. 'Background' => '',
  61. ),
  62. ),
  63. ));
  64. // 请求成功
  65. print_r($result);
  66. } catch (\Exception $e) {
  67. // 请求失败
  68. echo($e);
  69. }