tencent cloud

Generate Animated GIF
Last updated: 2025-12-26 10:29:32
Generate Animated GIF
Last updated: 2025-12-26 10:29:32

Feature Overview

Tencent Cloud Infinite provides a composite feature through the imageMogr2 interface, which can combine multiple images in jpg or png format into a GIF animation. This feature supports the following processing methods:
Processing upon download
Processing during upload
Cloud-based data processing

Authorization Description

When a sub-account is used, you need to add the corresponding permissions to the action of the authorization policy. For all API operations supported by COS, see COS action.
Processing upon download: set the action in the authorization policy to cos:GetObject.
Processing during upload: set the action in the authorization policy to cos:PutObject.
Cloud-based data processing: set the action in the authorization policy to cos:PutObject.
Note:
The resource corresponding to GetObject is the source file, while the resource corresponding to PutObject is the destination file.

Service Activation

When you first use this feature, Cloud Infinite will be enabled by default, and the Bucket will be automatically bound to Cloud Infinite without requiring role authorization, allowing direct use.
Note:
After Cloud Infinite is bound, if you manually unbind Cloud Infinite from the Bucket, you will not be able to continue using this feature.

Use Limits

When using this interface, please first confirm the relevant restrictions. For details, see Usage Limits.
The interface for animated image synthesis currently only applies to images stored in COS.
Supported formats for source images: jpg/jpeg, png.
The maximum number of frames supported: 20.
Limitations for source images: size not exceeding 32MB, dimensions not exceeding 1080*1080.

Fee Instructions

This interface is a paid service, and the incurred fees will be charged by Cloud Infinite. For detailed billing information, refer to Image Processing Fees.
If processing on download is adopted and the download is performed via the public network, Traffic Fees will be incurred.
This feature is included in the basic Image Processing usage, where the processing usage is calculated based on the sum of the original image sizes. For example, if 10 jpg images of 5MB each are used to synthesize an animated image, the usage is counted as 50MB.

API Examples

Processing upon Download

GET /<ObjectKey>?imageMogr2/animate/duration/<duration>/images/<imageurl1>/<imageurl2> HTTP/1.1
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com
Date: <GMT Date>
Authorization: <Auth String>
Note:
Spaces and line breaks in the preceding figure can be ignored.

Processing during upload

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/animate/duration/<duration>/images/<imageurl1>/<imageurl2>"
}]
}

Cloud-based data 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/animate/duration/<duration>/images/<imageurl1>/<imageurl2>"
}]
}
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.
Pic-Operations is a string in json format. For specific parameters, see Persistent Processing of Images.
When fileid and ObjectKey are the same, the processed image will overwrite the storage of the original image. When they are different, the original image and the processed image will be stored separately.
fileid value needs to be URLEncoded.

Description of Processing Parameters

Parameter
Parameter Description
Type
Required
ObjectKey
The file name in COS, such as folder/sample.jpg, will be used as the first frame of the synthesized animated image.
String
Yes
duration
The frame interval for GIF animated images (unit: ms) must be an integer greater than 0. For example, to set a 10ms interval, use the parameter /duration/10.
Int
Yes
images
The original image links to be synthesized, up to 19, must be URL-safe Base64 encoded. For example, if the encoded string for the first original image link is ahxxxxxxxxxmc and the second is wywxxxxxxxxjih, the parameter would be /images/ahxxxxxxxxxmc/wywxxxxxxxxjih.
String
Yes
Note:
If the original images to be synthesized have different sizes, the final synthesized animated image will proportionally scale all images based on the size of the first frame.

Practical Case

Note:
The practical examples in this document only include download-time processing. This type of processing does not save the processed images to the Bucket. If saving is required, see the persistent image processing document and configure upload-time processing or cloud data processing.
Using the image-1.jpg in Bucket examples-125xxxxxx as the first frame of the animated image, it is synthesized with image-2.jpg in the same Bucket into an animated image with a 50ms interval.
http://examples-125xxxxxx.cos.ap-shanghai.myqcloud.com/image-1.jpg?imageMogr2/animate/duration/50/images/aHR0cDovL2V4YW1wbGVzLTEyNXh4eHh4eC5jb3MuYXAtc2hhbmdoYWkubXlxY2xvdWQuY29tL2ltYWdlLTIuanBn

Must-Knows

To prevent unauthorized personnel from accessing and downloading original images by using links without processing parameters, you can include the processing parameters in the request signature. The processing parameters as a whole serve as the key with an empty value. Below is a simple example (for reference only; it may be expired and inaccessible). For detailed calculation methods, see Request Signature.
http://examples-1251000004.cos.ap-shanghai.myqcloud.com/sample.jpeg?q-sign-algorithm=sha1&q-ak=************************************&q-sign-time=1593342360;1593342720&q-key-time=1593342360;1593342720&q-header-list=&q-url-param-list=watermark%252f1%252fimage%252fahr0cdovl2v4yw1wbgvzlteyntewmdawmdqucgljc2gubxlxy2xvdwquy29tl3nodwl5aw4uanbn%252fgravity%252fsoutheast&q-signature=****************************************&watermark/1/image/aHR0cDovL2V4YW1wbGVzLTEyNTEwMDAwMDQucGljc2gubXlxY2xvdWQuY29tL3NodWl5aW4uanBn/gravity/southeast
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback