tencent cloud

Basic Image Compression (WebP)
Last updated: 2025-11-06 16:19:14
Basic Image Compression (WebP)
Last updated: 2025-11-06 16:19:14

Description

Image compression refers to reducing the image size as much as possible while maintaining the original image quality, thereby saving image storage space, reducing image access traffic, and improving image access speed.
Cloud Infinite (CI) introduced the WebP compression feature, which converts images into the WebP compressed format, outperforming JPG in compression. At the same image quality level, WebP images are over 25% smaller than JPG images, enabling adaptation to multi-terminal usage scenarios.

Authorization Description

When using a sub-account, you need to add the corresponding permission to the action in the authorization policy. For all supported API operations in Cloud Object Storage, see COS action.
Processing during download: Set action to cos:GetObject in the authorization policy.
Processing upon upload: Set action to cos:PutObject in the authorization policy.
Cloud data processing: Set action to cos:PutObject in the authorization policy.
Note:
GetObject resource is the source file, PutObject resource is the transferred file.

Service Activation

The first time you use this feature, Cloud Infinite (CI) will be activated for you by default, and the bucket will automatically bind CI with no need for role authorization, allowing you to use it directly.
Note:
After binding Cloud Infinite, if you manually perform bucket unbind for CI, you will not be able to continue using this function.

Use Limits

When using this API, please confirm the relevant restrictions. For details, see Usage Limits.

Fee Instructions

WebP compression is a paid service with the same fee as basic image processing. For specific fees, see Image Processing Fees. Generated costs will be charged by CI.
If processing during download is used and the download is performed via public network, traffic charges will occur.
Note:
After converting an image to WebP format, some browsers cannot read the exif data of WebP images, resulting in no rotation. See the rotation document and add the auto-orient parameter to rotate the original image before compression.
WebP compression inherits the original image's quality parameters by default. See the quality change document to adjust the compression rate by changing the image quality.

API Examples

Processing upon Download

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

Processing Upon 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",
"rule": "imageMogr2/format/webp"
}]
}

Cloud Data Processing

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",
"rule": "imageMogr2/format/webp"
}]
}
Note:
Authorization: A request header carrying authentication information to verify the validity of the request. The Pic-Operations header should be signed within the signature information. For details, see Request Signature.
Pic-Operations is a string in json format. For specific parameters, see Image Processing mechanism introduction.
When the fileid is the same as the ObjectKey, the output image will overwrite the input image for storage; otherwise, both the input and output images will be stored separately.
The value of fileid needs to be processed through URLEncode.

Processing Parameter Description

Parameter
Description
Type
Required or Not
ObjectKey
File name of the object, for example, folder/sample.jpg.
String
Yes
/format/<Format>
Compression format (here is WebP).
String
Yes

Practical Case

Note:
The practical cases in this document only include the Processing upon Download scenario. This type of processing does not save the output images to the bucket. If you need to save them, please use the Process upon Upload or Cloud Data Processing method.
Assume the input image is in PNG format with a size of 1335.2 KB, as shown in the figure below.

img


Convert the input image to WebP format. The request URL is as follows.
http://example-1258125638.cos.ap-shanghai.myqcloud.com/sample.png?imageMogr2/format/webp
The following figure shows the effect.

img


Compression Ratio Comparison
Format
Image Size
PNG (input image)
1335.2KB
WebP
65 KB (compression ratio: 95.13%)
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback