tencent cloud

Feedback

Basic Image Processing

Last updated: 2024-02-29 16:52:32

    Overview

    This document provides an overview of APIs and SDK code samples for basic image processing.
    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.

    Scaling

    Feature description

    CI uses the imageMogr2 API to scale images.

    Method prototype

    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)

    Sample request

    name := "test.jpg"
    // Sample 1. Get an object from the response body
    resp, 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 object
    filepath := "test.jpg"
    _, err = c.CI.GetToFile(context.Background(), name, filepath, "imageMogr2/thumbnail/!50px", nil)

    Parameter description

    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
    Object download parameters. For more information, see Object Operations.
    string
    No
    id
    Object VersionId
    string
    No

    Cropping

    Feature description

    CI uses the imageMogr2 API to crop images, including regular cropping, scaling and cropping, cropping to circle, rounded corner cropping, and smart face cropping.

    Sample request

    name := "test.jpg"
    filepath := "test.jpg"
    _, err = c.CI.GetToFile(context.Background(), name, filepath, "imageMogr2/cut/600x600x100x10", nil)

    Other Basic Image Processing Operations

    Feature description

    You can perform other basic processing operations on images by changing the value of the 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)
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support