Image compression is the process of downsizing an image as much as possible without sacrificing quality so that it can be stored at a lower cost and accessed more quickly.
COS launched the WebP compression feature based on CI to convert images to .webp format, which is superior to .jpg in terms of compression. A .webp image is over 25% smaller than a .jpg image with the same quality. This format is suitable for multi-terminal use cases.
COS uses CI's imageMogr2
API to provide the WebP compression feature.
This feature supports processing:
Note:
- WebP compression is a paid service charged by CI at the basic image processing prices. For detailed pricing, see Image Processing Fees.
- If an image is converted to WebP format, some browsers may not be able to read its EXIF data. As a result, the image cannot be rotated. You can add the
auto-orient
parameter to rotate the input image first before compressing it (see Rotation) .- WebP compression inherits the quality parameters of the input image by default. You can adjust the compression ratio by modifying the image quality as instructed in Quality Change.
GET /<ObjectKey>?imageMogr2/format/webp HTTP/1.1
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com
Date: <GMT Date>
Authorization: <Auth String>
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"
}]
}
Note:
Pic-Operations
is a JSON string. Its parameters are as described in Persistent Image 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: Auth String (for more information, see Request Signature).
- When this feature is used by a sub-account, relevant permissions must be granted. For more information, see Authorization Granularity Details.
Parameter | Description |
---|---|
ObjectKey | Object name, such as folder/sample.jpg . |
/format/<Format> | Compression format, which is webp here. |
Note:Processing during download is used as an example here, which does not store the output image in a bucket. If you need to store the output image, use processing during upload or processing in-cloud data instead.
Assume the input image is a 1,335.2 KB image in PNG format.
You can convert the image to WebP format by using the following request URL:
http://example-1258125638.cos.ap-shanghai.myqcloud.com/sample.png?imageMogr2/format/webp
Output:
Compression ratio comparison
Format | Image Size |
---|---|
PNG (input image) | 1,335.2 KB |
WebP | 65 KB (compression ratio: 95.13%) |
Apakah halaman ini membantu?