Skip to content

Commit 7d05b88

Browse files
author
franktguo
committed
ImageSlim
1 parent ea1f92f commit 7d05b88

File tree

6 files changed

+125
-7
lines changed

6 files changed

+125
-7
lines changed

sample/ImageSlim.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
4+
require dirname(__FILE__, 2) . '/vendor/autoload.php';
5+
6+
$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
7+
$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
8+
$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
9+
$cosClient = new Qcloud\Cos\Client(
10+
array(
11+
'region' => $region,
12+
'scheme' => 'https', //协议头部,默认为http
13+
'credentials' => array(
14+
'secretId' => $secretId,
15+
'secretKey' => $secretKey)));
16+
try {
17+
// 极智压缩
18+
$imageRule = new Qcloud\Cos\ImageParamTemplate\ImageSlimTemplate();
19+
$picOperations = new Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation();
20+
$picOperations->setIsPicInfo(1); // is_pic_info
21+
$picOperations->addRule($imageRule, "output.png"); // rules
22+
23+
// -------------------- 1. 下载时处理 -------------------- //
24+
// $downloadUrl = $cosClient->getObjectUrl('examplebucket-125000000', 'xxx.jpg'); // 获取下载链接
25+
$downloadUrl = 'https://examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/xxx.jpg'; // 私有图片处理方式同上,仅增加签名部分,并与图片处理参数以“&”连接
26+
$rule = $imageRule->queryString();
27+
echo "{$downloadUrl}?{$rule}";
28+
// echo "{$downloadUrl}&{$rule}"; // 携带签名的图片地址以“&”连接
29+
// -------------------- 1. 下载时处理 -------------------- //
30+
31+
// -------------------- 2. 上传时处理 -------------------- //
32+
$result = $cosClient->putObject(array(
33+
'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
34+
'Key' => 'object.jpg',
35+
'Body' => fopen('/tmp/local.jpg', 'rb'), // 本地文件
36+
'PicOperations' => $picOperations->queryString(),
37+
));
38+
// 请求成功
39+
print_r($result);
40+
// -------------------- 2. 上传时处理 -------------------- //
41+
42+
// -------------------- 3. 云上数据处理 -------------------- //
43+
$result = $cosClient->ImageProcess(array(
44+
'Bucket' => 'examplebucket-1250000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
45+
'Key' => 'test.png',
46+
'PicOperations' => $picOperations->queryString(),
47+
));
48+
// 请求成功
49+
print_r($result);
50+
// -------------------- 3. 云上数据处理 -------------------- //
51+
} catch (\Exception $e) {
52+
// 请求失败
53+
echo($e);
54+
}

sample/detectImage.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
$result = $cosClient->detectImage(array(
1818
'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
1919
'Key' => 'test.png', // 桶文件
20-
'ci-process' => 'sensitive-content-recognition',
2120
// 'BizType' => '', // 可选 定制化策略,不传走默认策略
2221
// 'Interval' => 5, // 可选 审核 GIF 时使用 截帧的间隔
2322
// 'MaxFrames' => 5, // 可选 针对 GIF 动图审核的最大截帧数量,需大于0。
@@ -32,10 +31,8 @@
3231

3332
//图片链接审核
3433
$imgUrl = 'https://test.jpg';
35-
$result = $cosClient->detectImage(array(
34+
$result = $cosClient->detectImageUrl(array(
3635
'Bucket' => 'examplebucket-125000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
37-
'Key' => '/', // 链接图片资源路径写 / 即可
38-
'ci-process' => 'sensitive-content-recognition',
3936
'DetectUrl' => $imgUrl,
4037
// 'BizType' => '', // 可选 定制化策略,不传走默认策略
4138
// 'Interval' => 5, // 可选 审核 GIF 时使用 截帧的间隔

src/Client.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
* @method object DescribeDocProcessJob(array $args) 查询文档转码任务
116116
* @method object GetDescribeDocProcessJobs(array $args) 拉取符合条件的文档转码任务
117117
* @method object DetectImage(array $args) 图片审核
118+
* @method object DetectImageUrl(array $args) 图片审核
118119
* @method object DetectImages(array $args) 图片审核-批量
119120
* @method object DetectVirus(array $args) 云查毒
120121
* @method object GetDetectVirusResult(array $args) 查询病毒检测任务结果

src/Descriptions.php

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4050,7 +4050,7 @@ public static function GetDescribeDocProcessJobsOutput() {
40504050
public static function DetectImage() {
40514051
return array(
40524052
'httpMethod' => 'GET',
4053-
'uri' => '/{Bucket}{/Key*}',
4053+
'uri' => '/{Bucket}{/Key*}?ci-process=sensitive-content-recognition',
40544054
'class' => 'Qcloud\\Cos\\Command',
40554055
'responseClass' => 'DetectImageOutput',
40564056
'responseType' => 'model',
@@ -4069,10 +4069,67 @@ public static function DetectImage() {
40694069
'Qcloud\\Cos\\Client::explodeKey'
40704070
)
40714071
),
4072-
'ci-process' => array(
4072+
'DetectType' => array(
4073+
'type' => 'string',
4074+
'location' => 'query',
4075+
'sentAs' => 'detect-type'
4076+
),
4077+
'DetectUrl' => array(
4078+
'type' => 'string',
4079+
'location' => 'query',
4080+
'sentAs' => 'detect-url'
4081+
),
4082+
'Interval' => array(
4083+
'type' => 'integer',
4084+
'location' => 'query',
4085+
'sentAs' => 'interval'
4086+
),
4087+
'MaxFrames' => array(
4088+
'type' => 'integer',
4089+
'location' => 'query',
4090+
'sentAs' => 'max-frames'
4091+
),
4092+
'BizType' => array(
4093+
'type' => 'string',
4094+
'location' => 'query',
4095+
'sentAs' => 'biz-type'
4096+
),
4097+
'LargeImageDetect' => array(
4098+
'type' => 'integer',
4099+
'location' => 'query',
4100+
'sentAs' => 'large-image-detect'
4101+
),
4102+
'DataId' => array(
4103+
'type' => 'string',
4104+
'location' => 'query',
4105+
'sentAs' => 'dataid'
4106+
),
4107+
'Async' => array(
4108+
'type' => 'integer',
4109+
'location' => 'query',
4110+
'sentAs' => 'async'
4111+
),
4112+
'Callback' => array(
4113+
'type' => 'string',
4114+
'location' => 'query',
4115+
'sentAs' => 'callback'
4116+
),
4117+
),
4118+
);
4119+
}
4120+
4121+
public static function DetectImageUrl() {
4122+
return array(
4123+
'httpMethod' => 'GET',
4124+
'uri' => '/{Bucket}?ci-process=sensitive-content-recognition',
4125+
'class' => 'Qcloud\\Cos\\Command',
4126+
'responseClass' => 'DetectImageOutput',
4127+
'responseType' => 'model',
4128+
'parameters' => array(
4129+
'Bucket' => array(
40734130
'required' => true,
40744131
'type' => 'string',
4075-
'location' => 'query'
4132+
'location' => 'uri',
40764133
),
40774134
'DetectType' => array(
40784135
'type' => 'string',
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Qcloud\Cos\ImageParamTemplate;
4+
class ImageSlimTemplate extends ImageTemplate {
5+
public function queryString() {
6+
return "imageSlim";
7+
}
8+
}

src/Service.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3710,6 +3710,7 @@ public static function getService() {
37103710
'DescribeDocProcessJob' => Descriptions::DescribeDocProcessJob(), // 查询文档转码任务
37113711
'GetDescribeDocProcessJobs' => Descriptions::GetDescribeDocProcessJobs(), // 拉取符合条件的文档转码任务
37123712
'DetectImage' => Descriptions::DetectImage(), // 图片审核
3713+
'DetectImageUrl' => Descriptions::DetectImageUrl(), // 图片审核
37133714
'DetectImages' => Descriptions::DetectImages(), // 图片审核-批量
37143715
'DetectVirus' => Descriptions::DetectVirus(), // 云查毒
37153716
'GetDetectVirusResult' => Descriptions::GetDetectVirusResult(), // 查询病毒检测任务结果

0 commit comments

Comments
 (0)