tencent cloud

Feedback

Basic Image Processing

Last updated: 2022-07-25 16:06:38

    Overview

    This document provides an overview of APIs and SDK code samples for basic image processing.

    API Description
    Scaling Scales up/down an image.
    Cropping Crops an image, including regular cropping, scaling and cropping, cropping to circle, rounded corner cropping, and smart face cropping.
    Rotation Rotates an image, including regular rotation and adaptive rotation.
    Format conversion Converts the format of an image, optimizes the GIF format, and performs progressive display.
    Quality change Adjusts the quality of an image.
    Gaussian blurring Blurs an image by a Gaussian function.
    Sharpening Sharpens an image.
    Image watermark Adds a watermark to an image.
    Text watermark Adds a real-time text watermark to an image.
    Basic image information acquisition Queries the basic information of an image, such as format, width, and height.
    Image EXIF data acquisition Queries the EXIF data of an image.
    Image average hue acquisition Queries the average hue of an image.
    Metadata removal Removes the image metadata, including the EXIF data.
    Quick thumbnail template Generates a thumbnail through an image processing template.
    Pipeline operator 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