createMediaWatermarkTemplate.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/54033 新增水印模板
  15. // 文本水印
  16. $result = $cosClient->createMediaWatermarkTemplate(array(
  17. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  18. 'Tag' => 'Watermark',
  19. 'Name' => 'Watermark-Template-Name',
  20. 'Watermark' => array(
  21. 'Type' => 'Text',
  22. 'Pos' => 'TopRight',
  23. 'LocMode' => 'Absolute',
  24. 'Dx' => '128',
  25. 'Dy' => '128',
  26. 'StartTime' => '',
  27. 'EndTime' => '',
  28. 'Text' => array(
  29. 'FontSize' => '30',
  30. 'FontType' => 'simfang',
  31. 'FontColor' => '0x000000',
  32. 'Transparency' => '30',
  33. 'Text' => '水印内容',
  34. ),
  35. ),
  36. ));
  37. // 请求成功
  38. print_r($result);
  39. // 图片水印
  40. $result = $cosClient->createMediaWatermarkTemplate(array(
  41. 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
  42. 'Tag' => 'Watermark',
  43. 'Name' => 'Watermark-Template-Name',
  44. 'Watermark' => array(
  45. 'Type' => 'Image',
  46. 'Pos' => 'TopRight',
  47. 'LocMode' => 'Absolute',
  48. 'Dx' => '128',
  49. 'Dy' => '128',
  50. 'StartTime' => '',
  51. 'EndTime' => '',
  52. 'Image' => array(
  53. 'Url' => 'https://examplebucket-125000000.cos.ap-guangzhou.myqcloud.com/test01.png',
  54. 'Mode' => 'Proportion',
  55. 'Width' => '10',
  56. 'Height' => '',
  57. 'Transparency' => '100',
  58. 'Background' => '',
  59. ),
  60. ),
  61. ));
  62. // 请求成功
  63. print_r($result);
  64. } catch (\Exception $e) {
  65. // 请求失败
  66. echo($e);
  67. }