Compression

This function is available for GUI, Code, and API calling mode.

To save space, you can compress images that are output in .jpg or .webp format. Table 1 describes the parameters in detail.

Operation name: quality

Table 1 Compression

Parameter

Value Description

Code Example

q

Relative quality of the image. The image is compressed to q% of the original. q ranges [1, 100].

Formula for compression: Target quality = Original quality x q%

For example, if the original quality of the image is 100% and the relative quality is 80%, then the target quality of the image is 80%. If the original quality of the image is 80% and the relative quality is 80%, then the target quality of the image is 64%.

image/resize,w_100,h_100/quality,q_80

Q

Absolute quality of the image. The image is compressed into Q%. Q has no relation with and does not depend on the original image. Q ranges [1, 100].

Formula for compression:

  • When Original quality > Q%, Target quality = Q%.
  • When Original quality = Q%, Target quality = Original quality = Q%.
  • When Original quality < Q%, Target quality = Original quality.

For example, if the original quality of the image is 100% and the absolute quality is 80%, then the target quality of the image is 100%. If the original quality of the image is 70% and the absolute quality is 80%, then the target quality of the image is 70%.

NOTE:
  • q is valid only for JPG images. For .webp images, the relative quality is equal to the absolute quality, and q is invalid when used alone.
  • If both q and Q are used, the output is based on Q.
  • q and Q are only valid for .jpg and .webp images. For images in other formats, q and Q bring no effect and cause no impact.

Example

  • Resize the image by setting the height and width both to 100, and output a jpg image with relative quality of 80%.

    https://obs.cn-north-1.myhwclouds.com/ya89soshla6s4uma-ims-example-cn-north-1/example.jpg?x-image-process=image/resize,w_100,h_100/quality,q_80

  • Resize the image by setting the height and width both to 100, and output a jpg image with absolute quality of 80%.

    https://obs.cn-north-1.myhwclouds.com/ya89soshla6s4uma-ims-example-cn-north-1/example.jpg?x-image-process=image/resize,w_100,h_100/quality,Q_80

Registration