This topic describes the rules for image processing, including image compression, format transforms, and color adjustments. You can use these rules to optimize image quality and processing efficiency.
Order independence
Key-value pairs in transform parameters are order-independent. For example, 120w_120h_90Q and 90Q_120w_120h produce the same image. Before processing, the system reorders parameters according to the sequence defined in the documentation. For example, 2x_100w_100h is interpreted as 100w_100h_2x and results in a 200 × 200 image.
Overwrite handling
If the same key appears multiple times in the transform parameters, the last instance overwrites the previous ones. For example, 120w_120h_240w is equivalent to 120h_240w.
Conflict handling
For more information about conflicts, see the description for each parameter.
Long and short edges
When you scale an image, the aspect ratio of the original image might differ from the target dimensions. You must specify whether to scale the image based on its long or short edge. For example, consider scaling a 200 × 400 image (1:2 aspect ratio) to 100 × 100 (1:1 aspect ratio). If you prioritize the long edge (e=0), the image is scaled to 50 × 100. If you prioritize the short edge (e=1), the image is scaled to 100 × 200. If you do not specify this parameter, the long edge is used by default.
URL-safe Base64 encoding
Many parameters in the image processing service require Base64 encoding. For more information, see RFC4648. Note that URL-safe Base64 encoding is used only for specific watermark parameters, such as the text, color, and font for text watermarks, and the watermark object for image watermarks. Do not use this encoding for the content of the signature string (Signature).
Encode the content into a Base64 string.
Replace all plus signs (+) with hyphens (-).
Replace all forward slashes (/) with underscores (_).
Remove any trailing equal signs (=).
This topic uses Python as an example.
import base64
text_input = 'wqy-microhei'
encoded_result = base64.urlsafe_b64encode(text_input.encode('utf-8')).decode('utf-8').rstrip('=')