|
17 | 17 | $blindWatermarkTemplate->setImage("http://examplebucket-125000000.cos.ap-beijing.myqcloud.com/shuiyin.jpeg"); |
18 | 18 | $blindWatermarkTemplate->setType(2); |
19 | 19 | $blindWatermarkTemplate->setLevel(3); |
| 20 | + |
| 21 | + // -------------------- 1. 下载时处理 -------------------- // |
20 | 22 | $result = $cosClient->getObject(array( |
21 | 23 | 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket |
22 | 24 | 'Key' => 'exampleobject', |
|
25 | 27 | )); |
26 | 28 | // 请求成功 |
27 | 29 | print_r($result); |
| 30 | + // -------------------- 1. 下载时处理 -------------------- // |
| 31 | + |
| 32 | + // -------------------- 2. 上传时处理 -------------------- // |
| 33 | + $local_path = "/data/exampleobject"; |
| 34 | + $picOperationsTemplate = new Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation(); |
| 35 | + $picOperationsTemplate->setIsPicInfo(1); |
| 36 | + $picOperationsTemplate->addRule($blindWatermarkTemplate, "resultobject"); |
| 37 | + $result = $cosClient->putObject(array( |
| 38 | + 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket |
| 39 | + 'Key' => 'exampleobject', |
| 40 | + 'Body' => fopen($local_path, 'rb'), |
| 41 | + 'PicOperations' => $picOperationsTemplate->queryString(), |
| 42 | + )); |
| 43 | + // 请求成功 |
| 44 | + print_r($result); |
| 45 | + // -------------------- 2. 上传时处理 -------------------- // |
| 46 | + |
| 47 | + // -------------------- 3. 云上数据处理 -------------------- // |
| 48 | + $result = $cosClient->ImageProcess(array( |
| 49 | + 'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket |
| 50 | + 'Key' => 'exampleobject', |
| 51 | + 'PicOperations' => $picOperationsTemplate->queryString(), |
| 52 | + )); |
| 53 | + // 请求成功 |
| 54 | + print_r($result); |
| 55 | + // -------------------- 3. 云上数据处理 -------------------- // |
28 | 56 | } catch (\Exception $e) { |
29 | 57 | // 请求失败 |
30 | 58 | echo($e); |
|
0 commit comments