图片高级压缩
最近更新时间:2021-11-18 11:33:51
简介
本文档提供关于图片高级压缩的 API 概览以及 SDK 示例代码。
API |
操作描述 |
图片高级压缩 |
图片高级压缩可以更加高效地将图片转换为 TPG 或 HEIF 等高压缩比格式,有效降低图片传输链路及加载耗时,降低带宽及流量成本 |
图片高级压缩
功能说明
通过数据万象 imageMogr2 接口提供图片高级压缩功能。
示例代码
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
$secretId = "SECRETID";
$secretKey = "SECRETKEY";
$region = "ap-beijing";
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'schema' => 'https',
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));
try {
$imageMogrTemplate = new Qcloud\Cos\ImageParamTemplate\ImageMogrTemplate();
$imageMogrTemplate->format('tpg');
$imageMogrTemplate->format('heif');
$result = $cosClient->getObject(array(
'Bucket' => 'examplebucket-1250000000',
'Key' => 'exampleobject',
'ImageHandleParam' => $imageMogrTemplate->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 |
是 |
ImageHandleParam |
String |
万象图片处理参数,例如:imageMogr2/format/tpg |
是 |
返回结果示例
Guzzle\Service\Resource\Model Object
(
[structure:protected] =>
[data:protected] => Array
(
[Body] =>
[ETag] => "698d51a19d8a121ce581499d7b701668"
[RequestId] => NWQwOGRkNDdfMjJiMjU4NjRfNzVjXzEwNmVjY2M=
[ContentLength] => 100
[ContentType] => image/jpeg
[Key] => exampleobject
[Bucket] => examplebucket-1250000000
[Location] => examplebucket-1250000000.cos.ap-beijing.myqcloud.com/exampleobject
)
)
返回结果说明
参数名称 |
类型 |
描述 |
父节点 |
Body |
File/String |
下载内容 |
无 |
ETag |
String |
文件的 MD5 值 |
无 |
ContentLength |
Int |
响应体长度 |
无 |
ContentType |
String |
内容类型,设置 Content-Type |
无 |
RequestId |
String |
请求 ID 标识 |
无 |
Key |
String |
对象键 |
无 |
Bucket |
String |
存储桶名称,格式:BucketName-APPID |
无 |
Location |
String |
请求资源地址 |
无 |