You can use the format parameter to convert the format of a source image that is stored in Object Storage Service (OSS). This topic describes the format parameter and provides examples on how to convert the format of an image.
Parameter description
Parameter name: format.
The following table describes the valid values of the format parameter.
Valid value | Description |
---|---|
jpg | Saves the source image in the JPG format. Important Images in the HEIC format that support alpha channels cannot be saved in the JPG format. |
png | Saves the source image in the PNG format. |
webp | Saves the source image in the WebP format. |
bmp | Saves the source image in the BMP format. |
gif | Saves the source image in the GIF format. If the source image is not in the GIF format, the image is saved in the original format. |
tiff | Saves the source image in the TIFF format. |
- If the source image does not support alpha channels, the format of the source image is converted to a format that supports alpha channels. Formats that support alpha channels include PNG, WebP, and BMP. By default, OSS fills the transparent area in white.
- You cannot use OSS to fill the transparent area in black.
Usage notes
- When you perform a standard resize operation on an image, we recommend that you add the format parameter to the end of the Image Processing (IMG) parameter.
Example:
image/resize,w_100/format,jpg
- When you resize and watermark an image, we recommend that you add the format parameter to the end of the resize parameter.
Example:
image/reisze,w_100/format,jpg/watermark,...
Examples
You can process images by using object URLs, OSS SDKs, or API operations. In this example, object URLs are used. For more information about how to use OSS SDKs and API operations to process images, see IMG implementation modes.
In the following examples, an image in a bucket named image-demo in the China (Hangzhou) region is used as the source image. The image can be accessed over the Internet by using the following URL:
- Convert the format of the source image to PNGThe URL used to process the image: https://image-demo.oss-cn-hangzhou.aliyuncs.com/example.gif?x-oss-process=image/format,png
- Convert the format of the source image to JPG that supports gradual displayConfigure the parameters based on the following requirements:
- The parameter used to set the image to gradual display:
interlace,1
- The parameter used to convert the format of the image to JPG:
format,jpg
The URL used to process the image: https://image-demo.oss-cn-hangzhou.aliyuncs.com/example.gif?x-oss-process=image/interlace,1/format,jpg
- The parameter used to set the image to gradual display:
- Resize the image to a width of 200 pixels and convert the format of the image to WebPConfigure the parameters based on the following requirements:
- The parameter used to resize the image to a width of 200 pixels:
resize,w_200
- The parameter used to convert the format of the image to WebP:
format,webp
The URL used to process the image: https://image-demo.oss-cn-hangzhou.aliyuncs.com/example.gif?x-oss-process=image/resize,w_200/format,webp - The parameter used to resize the image to a width of 200 pixels:
FAQ
What do I do if black borders appear when the image format is being converted?
The image format has a default quality. If no quality is specified during format conversion, the image format is converted based on the default quality. In this case, black borders may appear in the image.
If you want to improve the image quality, we recommend that you set the image quality parameter to 100(?x-oss-process=image/quality,Q_100). For more information, see Adjust image quality.
Does the image format conversion affect the page loading speed?
The image format conversion affects the page loading speed.