tencent cloud

Cloud Infinite

Using Smart Compression through API

PDF
フォーカスモード
フォントサイズ
最終更新日: 2026-01-19 11:34:40

Feature Description

Smart Image Compression intelligently determines the subjective quality of images and performs automatic adjustment. Without changing the original format of the image, it significantly reduces the file size compared to the original while maintaining the visual quality as close to the original as possible. This helps you reduce image access traffic and improve image loading speed. The feature supports the following processing methods:
Processing during download
Processing during upload
Processing in the cloud

Authorization Description

When used with a sub-account, the ci:SetImageSlim permission is required. For details, see Cloud Infinite action.
Process during download: Set action to cos:GetObject in the authorization policy.
Process upon upload: Set action to cos:PutObject in the authorization policy.
Process data in the cloud: Set action to cos:PutObject in the authorization policy.
Note:
The resource for GetObject corresponds to the source file, and the resource for PutObject corresponds to the transferred file.

Service Activation

Using this feature requires enabling Cloud Infinite in advance and binding a bucket. For details, see Binding a Bucket.
Use this feature requires enabling the Smart Compression API functionality in advance via the console or API. For details, see Smart Image Compression.

Use Limits

When using this API, please confirm the relevant restrictions first. For details, see Specifications and Limits.
Does not support processing images in COS Archive Storage or Deep Archive Storage. If you need to process such files, please restore archived files.

Fee Description

Smart Image Compression is a paid service. The incurred fees will be collected by Cloud Infinite. For detailed billing information, see Image Processing Fees.
If "process during download" is adopted and the download is performed via the public network, the call will incur traffic charges.
If the image is stored in the COS Infrequent Access storage, the API call will generate COS data retrieval fees.

Interface Format

Processing during download

GET /<ObjectKey>?imageSlim HTTP/1.1
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com
Date: <GMT Date>
Authorization: <Auth String>

Processing during upload

PUT /<ObjectKey> HTTP/1.1
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com
Date: GMT Date
Authorization: Auth String
Pic-Operations:
{
"is_pic_info": 1,
"rules": [{
"fileid": "exampleobject.jpg",
"rule": "imageSlim"
}]
}

Processing in the cloud

POST /<ObjectKey>?image_process HTTP/1.1
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com
Date: GMT Date
Content-length: Size
Authorization: Auth String
Pic-Operations:
{
"is_pic_info": 1,
"rules": [{
"fileid": "exampleobject.jpg",
"rule": "imageSlim"
}]
}
Note:
Authorization: Carries authentication information for verifying the legitimacy of requests. The Pic-Operations header must include the signature information. For details, see the Request Signature document.
Pic-Operations is a JSON format string. Specific parameter information can be found in Image Processing Mechanism Introduction.
When fileid is the same as ObjectKey, the processed image will overwrite the original stored image; when they are different, the original image and the processed image will be stored separately.
The value of fileid needs to be URL-encoded.

Processing Parameter Description

Parameter
Definition
Required
ObjectKey
Object file name, for example: folder/sample.jpg.
Yes
imageSlim
Fixed parameters, means smart compression.
Yes
Note:
When using processing during download, you can determine whether the image has been compressed by checking the X-Slimflag response header. This response header contains the following three values:
0: Indicates compression failed;
1: Indicates compression succeeded;
2: Indicates no compression was performed, and the original image was returned.

Real Case

Note:
The actual cases in this document contain only processing during download. This type of processing will not save the processed images to the bucket. If you need saving, you can refer to the Image Processing Mechanism Introduction document and configure processing during upload or processing in the cloud.
Assume the original image format is png, the image size is 1335.2 KB, as shown below:

img


Perform Smart Image Compression on the image, the request URL is as follows:
http://example-1258125638.cos.ap-shanghai.myqcloud.com/sample.png?imageSlim
Output:

img


Compression Rate Comparison
Format
Image Size
png (original image)
1335.2KB
png (Smart Compressed image)
549KB (compression rate 58.88%)

ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック