tencent cloud

Feedback

Persistent Image Processing

Last updated: 2024-03-01 14:57:12

    Overview

    This document provides an overview of APIs and SDK code samples related to persistent image processing.
    API
    Description
    Processes an image during upload, or processes an image stored in COS and saves the processing result to COS. Images within 32 MB can be processed.

    Processing upon Upload

    Feature description

    CI allows you to process images during upload. To enable this, add Pic-Operations to the request header and set relevant parameters. You can also save the input images and processing results to COS.

    Method prototype

    ci_put_object(self, Bucket, Body, Key, EnableMD5=False, **kwargs)

    Sample request

    with open('local.jpg', 'rb') as fp:
    response, data = client.ci_put_object(
    Bucket='examplebucket-1250000000',
    Body=fp,
    Key=ci_file_name,
    # pic operation json struct
    PicOperations='{"is_pic_info":1,"rules":[{"fileid":"format.png","rule":"imageView2/format/png"}]}')

    Sample request with all parameters

    response = client.ci_put_object(
    Bucket='examplebucket-1250000000',
    Body=b'bytes'|file,
    Key='exampleobject',
    EnableMD5=False|True,
    ACL='private'|'public-read', # Please note that the maximum number (1000) of ACLs allowed may be reached if you use this parameter
    GrantFullControl='string',
    GrantRead='string',
    StorageClass='STANDARD'|'STANDARD_IA'|'ARCHIVE',
    Expires='string',
    CacheControl='string',
    ContentType='string',
    ContentDisposition='string',
    ContentEncoding='string',
    ContentLanguage='string',
    ContentLength='123',
    ContentMD5='string',
    Metadata={
    'x-cos-meta-key1': 'value1',
    'x-cos-meta-key2': 'value2'
    },
    TrafficLimit='1048576'
    PicOperations='{"is_pic_info":1,"rules":[{"fileid":"format.png","rule":"imageView2/format/png"}]}'
    )

    Parameter description

    Parameter
    Description
    Type
    Required
    Bucket
    Bucket name in the format of BucketName-APPID.
    String
    Yes
    Body
    Content of the uploaded object, which can be a file stream or a byte stream.
    file/bytes
    Yes
    Key
    Object key, which uniquely identifies an object in a 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
    PicOperations
    CI image processing parameter. For more information, see Persistent Image Processing.
    String
    Yes
    EnableMD5
    Whether the SDK needs to calculate the Content-MD5 checksum. It is disabled by default. The upload will take longer if it is enabled.
    Bool
    No
    ACL
    Sets the object ACL, such as private or public-read.
    String
    No
    GrantFullControl
    Grants full permission in the format of id="OwnerUin".
    String
    No
    GrantRead
    Grants read permission in the format of id="OwnerUin".
    String
    No
    StorageClass
    Sets the storage class of the object, such as STANDARD (default), STANDARD_IA, and ARCHIVE. For more information, see Storage Class Overview.
    String
    No
    Expires
    Sets Expires.
    String
    No
    CacheControl
    Cache policy. Sets Cache-Control.
    String
    No
    ContentType
    Content type. Sets Content-Type.
    String
    No
    ContentDisposition
    Object name. Sets Content-Disposition.
    String
    No
    ContentEncoding
    Encoding format. Sets Content-Encoding.
    String
    No
    ContentLanguage
    Language type. Sets Content-Language.
    String
    No
    ContentLength
    Sets the length of the request content.
    String
    No
    ContentMD5
    Sets the MD5 checksum of the uploaded object for verification.
    String
    No
    Metadata
    User-defined object metadata. It must start with x-cos-meta; otherwise, it will be ignored.
    Dict
    No
    TrafficLimit
    Bandwidth limit for a single request in bit/s. Value range: 819200-838860800, i.e., 100 KB/s–100 MB/s.
    String
    No
    PicOperations is a JSON string. Its parameters are as follows:
    Parameter
    Description
    Type
    Required
    is_pic_info
    Whether to return the input image information. Valid values: 0 (no), 1 (yes). Default value: 0.
    Int
    No
    rules
    Processing rules (up to five rules are supported). Each rule corresponds to one processing result. If this parameter is not specified, images will not be processed.
    Array
    No
    Parameters of rules (a JSON array) are as follows:
    Parameter
    Description
    Type
    Required
    bucket
    Name of the destination bucket to store the results in the format of BucketName-APPID. If this parameter is not specified, the results will be stored in the current bucket by default.
    String
    No
    fileid
    Path of the processing result file. If the path starts with /, the result file will be stored in the specified folder; otherwise, it will be stored in the same directory as the input image file.
    String
    Yes
    rule
    Processing parameters. For more information, see CI's image processing API. To process an image by using a specified style, the value must start with style/, with the style name followed. For example, if the style name is test, the value of rule should be style/test.
    String
    Yes

    Response description

    The response contains the original image and processing information in dict format:
    {
    'OriginalInfo': {
    'Key': 'local.jpg',
    'Location': 'examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/local.jpg',
    'ETag': '"aff1b996bcc63a0f0259df0de2fa989f38c5ce7e"',
    'ImageInfo': {
    'Format': 'JPEG',
    'Width': '300',
    'Height': '168',
    'Quality': '74',
    'Ave': '0x1a3451',
    'Orientation': '0'
    'FrameCount': '1'
    }
    },
    'ProcessResults': {
    'Object': {
    'Key': 'format.png',
    'Location': 'examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/format.png',
    'Format': 'png',
    'Width': '300',
    'Height': '168',
    'Size': '77063',
    'Quality': '74',
    'ETag': '"a07dc5bcfa238e7d23d2d5884da4ac328aaaa9c6"'
    'FrameCount': '1'
    }
    }
    }
    Parameters in the response body are as follows:
    Parameter
    Type
    Description
    UploadResult
    Container
    Input image information
    Content of UploadResult:
    Parameter
    Type
    Description
    OriginalInfo
    Container
    Input image information
    ProcessResults
    Container
    Image processing result
    Content of OriginalInfo:
    Node Name
    Type
    Description
    Key
    String
    Input image name
    Location
    String
    Image path
    ImageInfo
    Container
    Input image information
    ETag
    String
    ETag of the input image. If the output image overwrites the input image, the value of ETag will be that of the output image.
    Content of ImageInfo:
    Node Name
    Type
    Description
    Format
    String
    Format
    Width
    Int
    Image width
    Height
    Int
    Image height
    Quality
    Int
    Image quality
    Ave
    String
    Image average hue
    Orientation
    Int
    Image rotation angle
    FrameCount
    Int
    Number of frames of the image, which is 1 for static images by default.
    Content of ProcessResults:
    Node Name
    Type
    Description
    Object
    Container
    Processing result of each image
    Content of Object:
    Node Name
    Type
    Description
    Key
    String
    File name
    Location
    String
    Image path
    Format
    String
    Image format
    Width
    Int
    Image width
    Height
    Int
    Image height
    Size
    Int
    Image size
    Quality
    Int
    Image quality
    ETag
    String
    ETag of the processing result image
    FrameCount
    Int
    Number of frames of the image, which is 1 for static images by default.

    Processing In-Cloud Data

    Feature description

    The persistent image processing API can process an in-cloud image and save the processing result to COS.

    Method prototype

    ci_image_process(self, Bucket, Key, **kwargs)

    Sample request

    response, data = client.ci_image_process(
    Bucket='examplebucket-1250000000',
    Key=ci_file_name,
    # pic operation json struct
    PicOperations='{"is_pic_info":1,"rules":[{"fileid":"format.png","rule":"imageView2/format/png"}]}')

    Sample request with all parameters

    response, data = client.ci_image_process(
    Bucket='examplebucket-1250000000',
    Key=ci_file_name,
    # pic operation json struct
    PicOperations='{"is_pic_info":1,"rules":[{"fileid":"format.png","rule":"imageView2/format/png"}]}')

    Parameter description

    Parameter
    Description
    Type
    Required
    Bucket
    Bucket name in the format of BucketName-APPID.
    String
    Yes
    Key
    Object key, which uniquely identifies an object in a 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
    PicOperations
    CI image processing parameters. For more information, see Persistent Image Processing.
    String
    Yes
    PicOperations is a JSON string. Its parameters are as follows:
    Parameter
    Description
    Type
    Required
    is_pic_info
    Whether to return the input image information. Valid values: 0 (no), 1 (yes). Default value: 0.
    Int
    No
    rules
    Processing rules (up to five rules are supported). Each rule corresponds to one processing result. If this parameter is not specified, images will not be processed.
    Array
    No
    Parameters of rules (a JSON array) are as follows:
    Parameter
    Description
    Type
    Required
    bucket
    Name of the destination bucket to store the results in the format of BucketName-APPID. If this parameter is not specified, the results will be stored in the current bucket by default.
    String
    No
    fileid
    Path of the processing result file. If the path starts with /, the result file will be stored in the specified folder; otherwise, it will be stored in the same directory as the input image file.
    String
    Yes
    rule
    Processing parameters. For more information, see the image processing API. To process an image by using a specified style, the value must start with style/ with the style name followed. For example, if the style name is test, the value of rule should be style/test.
    String
    Yes

    Response description

    The response contains object metadata in dict format:
    {
    'OriginalInfo': {
    'Key': 'local.jpg',
    'Location': 'examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/local.jpg',
    'ETag': '"aff1b996bcc63a0f0259df0de2fa989f38c5ce7e"',
    'ImageInfo': {
    'Format': 'JPEG',
    'Width': '300',
    'Height': '168',
    'Quality': '74',
    'Ave': '0x1a3451',
    'Orientation': '0'
    'FrameCount': '1'
    }
    },
    'ProcessResults': {
    'Object': {
    'Key': 'format.png',
    'Location': 'examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/format.png',
    'Format': 'png',
    'Width': '300',
    'Height': '168',
    'Size': '77063',
    'Quality': '74',
    'ETag': '"a07dc5bcfa238e7d23d2d5884da4ac328aaaa9c6"'
    'FrameCount': '1'
    }
    }
    }
    Parameters in the response body are as follows:
    Parameter
    Type
    Description
    UploadResult
    Container
    Input image information
    Content of UploadResult:
    Parameter
    Type
    Description
    OriginalInfo
    Container
    Input image information
    ProcessResults
    Container
    Image processing result
    Content of OriginalInfo:
    Node Name
    Type
    Description
    Key
    String
    Input image name
    Location
    String
    Image path
    ImageInfo
    Container
    Input image information
    ETag
    String
    ETag of the input image. If the output image overwrites the input image, the value of ETag will be that of the output image.
    Content of ImageInfo:
    Node Name
    Type
    Description
    Format
    String
    Format
    Width
    Int
    Image width
    Height
    Int
    Image height
    Quality
    Int
    Image quality
    Ave
    String
    Image average hue
    Orientation
    Int
    Image rotation angle
    FrameCount
    Int
    Number of frames of the image, which is 1 for static images by default.
    Content of ProcessResults:
    Node Name
    Type
    Description
    Object
    Container
    Processing result of each image
    Content of Object:
    Node Name
    Type
    Description
    Key
    String
    File name
    Location
    String
    Image path
    Format
    String
    Image format
    Width
    Int
    Image width
    Height
    Int
    Image height
    Size
    Int
    Image size
    Quality
    Int
    Image quality
    ETag
    String
    ETag of the processing result image
    FrameCount
    Int
    Number of frames of the image, which is 1 for static images by default.
    
    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