API | Description |
Scales up/down an image. | |
Crops an image, including regular cropping, scaling and cropping, cropping to circle, rounded corner cropping, and smart face cropping. | |
Rotates an image, including regular rotation and adaptive rotation. | |
Converts the format of an image, optimizes the GIF format, and performs progressive display. | |
Adjusts the quality of an image. | |
Blurs an image by a Gaussian function. | |
Sharpens an image. | |
Adds a watermark to an image. | |
Adds a real-time text watermark to an image. | |
Queries the basic information of an image, such as format, width, and height. | |
Queries the EXIF data of an image. | |
Queries the average hue of an image. | |
Removes the image metadata, including the EXIF data. | |
Generates a thumbnail through an image processing template. | |
Performs multiple operations on an image in sequence. |
func (s *CIService) Get(ctx context.Context, key string, operation string, opt *ObjectGetOptions, id ...string) (*Response, error)func (s *CIService) GetToFile(ctx context.Context, key, localpath, operation string, opt *ObjectGetOptions, id ...string) (*Response, error)
name := "test.jpg"// Sample 1. Get an object from the response bodyresp, err := c.CI.Get(context.Background(), name, "imageMogr2/thumbnail/!50px", nil)if err != nil {//ERROR}defer resp.Body.Close()ioutil.ReadAll(resp.Body)// Sample 2. Download an objectfilepath := "test.jpg"_, err = c.CI.GetToFile(context.Background(), name, filepath, "imageMogr2/thumbnail/!50px", nil)
Parameter | Description | Type | Required |
key | Unique identifier of the object in the bucket. For example, if an object's access endpoint is examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg , its key is doc/pic.jpg . | string | Yes |
operation | Image processing operation, such as scaling, cropping, rotation, format conversion, and quality change. | string | Yes |
ObjectGetOptions | string | No | |
id | Object VersionId | string | No |
name := "test.jpg"filepath := "test.jpg"_, err = c.CI.GetToFile(context.Background(), name, filepath, "imageMogr2/cut/600x600x100x10", nil)
operation
parameter. For example, you can rotate the image clockwise by 90 degrees as follows:name := "test.jpg"filepath := "test.jpg"_, err = c.CI.GetToFile(context.Background(), name, filepath, "imageMogr2/rotate/90", nil)
Apakah halaman ini membantu?