Basic Image Compression (WebP)

Last Updated At: 2026-08-14 08:08:00

Feature 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.
The WebP compression feature can convert images into the WebP compressed format, which is superior to JPG in compression performance. At the same image quality level, WebP images are over 25% smaller than JPG images, enabling adaptation to multi-terminal use cases.

API Examples

Processing upon Download

GET /<ObjectKey>?imageMogr2/format/webp HTTP/1.1
Host: <BucketName>.<Endpoint>
Date: <GMT Date>
Authorization: <Auth String>

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.
  • 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
ObjectKey File name of the object. For example, folder/sample.jpg. String Yes
/format/ Compression format (here is WebP). String Yes

Practical Cases

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.

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.city.yfm4.fsphere.cn/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%)