简介
本文档提供关于图片持久化处理的 API 概览以及 SDK 示例代码。
图片持久化处理 |
对象存储(Cloud Object Storage,COS)提供的上传时处理功能可以帮助使用者在上传时实现图片处理。此外能够对已存储在 COS 的图片进行相应处理操作,并将结果存入到 COS |
上传时处理
示例代码
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
$secretId = "SECRETID"; $secretKey = "SECRETKEY"; $region = "ap-beijing"; $cosClient = new Qcloud\Cos\Client( array( 'region' => $region, 'scheme' => 'https', 'credentials'=> array( 'secretId' => $secretId , 'secretKey' => $secretKey)));
try { $imageMogrTemplate = new Qcloud\Cos\ImageParamTemplate\ImageMogrTemplate(); $imageMogrTemplate->thumbnailByScale(50); $picOperationsTemplate = new \Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation(); $picOperationsTemplate->setIsPicInfo(1); $picOperationsTemplate->addRule($imageMogrTemplate, "resultobject"); $result = $cosClient->putObject(array( 'Bucket' => 'examplebucket-1250000000', 'Key' => 'exampleobject', 'Body' => fopen('path/to/localFile', 'rb'), 'PicOperations' => $picOperationsTemplate->queryString(), )); print_r($result);} catch (\Exception $e) { echo($e);}
参数说明
Bucket |
String |
存储桶名称,格式:BucketName-APPID |
是 |
Key |
String |
此处的 Key 为对象键,对象键是对象在存储桶中的唯一标识。例如,在对象的访问域名examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg 中,对象键为doc/pic.jpg |
是 |
Body |
File/String |
上传的内容 |
是 |
PicOperations |
Json/String |
图片持久化处理信息 |
是 |
返回结果示例
Guzzle\Service\Resource\Model Object( [structure:protected] => [data:protected] => Array ( [Body] => [ETag] => "698d51a19d8a121ce581499d7b701668" [RequestId] => NWQwOGRkNDdfMjJiMjU4NjRfNzVjXzEwNmVjY2M= [ContentLength] => 238186 [Key] => exampleobject [Bucket] => examplebucket-1250000000 [Location] => examplebucket-1250000000.cos.ap-beijing.myqcloud.com/exampleobject [Data] => Array ( [OriginalInfo] => Array ( [Key] => exampleobject [Location] => examplebucket-1250000000.cos.ap-beijing.myqcloud.com/exampleobject [ETag] => "7037fb6fb4cca43b958a28789605e73d98088720" [ImageInfo] => Array ( [Format] => JPEG [Width] => 600 [Height] => 500 [Quality] => 90 [Ave] => 0x46442e [Orientation] => 0 )
) [ProcessResults] => Array ( [Object] => Array ( [0] => Array( [Key] => resultobject [Location] => examplebucket-1250000000.cos.ap-beijing.myqcloud.com/resultobject [Format] => JPEG [Width] => 300 [Height] => 200 [Size] => 30000 [Quality] => 90 [ETag] => "87c153bc2909aa0ba111ca126b675c510d36b817" ) ) ) ) ))
返回结果说明
Body |
File/String |
返回体 |
无 |
ETag |
String |
文件的 MD5 值 |
无 |
RequestId |
String |
请求 ID 标识 |
无 |
ContentLength |
Int |
响应体长度 |
无 |
Key |
String |
对象键 |
无 |
Bucket |
String |
存储桶名称,格式:BucketName-APPID |
无 |
Location |
String |
请求资源地址 |
无 |
Data |
Array |
图片处理结果信息 |
无 |
云上数据处理
示例代码
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
$secretId = "SECRETID"; $secretKey = "SECRETKEY"; $region = "ap-beijing"; $cosClient = new Qcloud\Cos\Client( array( 'region' => $region, 'scheme' => 'https', 'credentials'=> array( 'secretId' => $secretId , 'secretKey' => $secretKey)));
try { $imageMogrTemplate = new Qcloud\Cos\ImageParamTemplate\ImageMogrTemplate(); $imageMogrTemplate->thumbnailByScale(50); $picOperationsTemplate = new \Qcloud\Cos\ImageParamTemplate\PicOperationsTransformation(); $picOperationsTemplate->setIsPicInfo(1); $picOperationsTemplate->addRule($imageMogrTemplate, "resultobject"); $result = $cosClient->ImageProcess(array( 'Bucket' => 'examplebucket-1250000000', 'Key' => 'exampleobject', 'PicOperations' => $picOperationsTemplate->queryString(), )); print_r($result);} catch (\Exception $e) { echo($e);}
参数说明
Bucket |
String |
存储桶名称,格式:BucketName-APPID |
是 |
Key |
String |
此处的 Key 为对象键,对象键是对象在存储桶中的唯一标识。例如,在对象的访问域名examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg 中,对象键为doc/pic.jpg |
是 |
PicOperations |
Json/String |
图片持久化处理信息 |
是 |
返回结果示例
Guzzle\Service\Resource\Model Object( [structure:protected] => [data:protected] => Array ( [RequestId] => NWQwOGRkNDdfMjJiMjU4NjRfNzVjXzEwNmVjY2M= [Key] => exampleobject [Bucket] => examplebucket-1250000000 [Location] => examplebucket-1250000000.cos.ap-beijing.myqcloud.com/exampleobject [OriginalInfo] => Array ( [Key] => exampleobject [Location] => examplebucket-1250000000.cos.ap-beijing.myqcloud.com/exampleobject [ETag] => "7037fb6fb4cca43b958a28789605e73d98088720" [ImageInfo] => Array ( [Format] => JPEG [Width] => 600 [Height] => 500 [Quality] => 90 [Ave] => 0x46442e [Orientation] => 0 )
) [ProcessResults] => Array ( [Object] => Array ( [0] => Array( [Key] => resultobject [Location] => examplebucket-1250000000.cos.ap-beijing.myqcloud.com/resultobject [Format] => JPEG [Width] => 300 [Height] => 200 [Size] => 30000 [Quality] => 90 [ETag] => "87c153bc2909aa0ba111ca126b675c510d36b817" ) ) ) ))
返回结果说明
RequestId |
String |
请求 ID 标识 |
无 |
Key |
String |
对象键 |
无 |
Bucket |
String |
存储桶名称,格式:BucketName-APPID |
无 |
Location |
String |
请求资源地址 |
无 |
OriginalInfo |
Array |
源图片信息 |
无 |
ProcessResults |
Array |
图片处理结果信息 |
无 |
对象存储官网1折活动,限时活动,即将结束,速速收藏
同尘科技为腾讯云授权服务中心。
购买腾讯云产品享受折上折,更有现金返利。同意关联立享优惠
转转请注明出处:https://www.yunxiaoer.com/145940.html