tencent cloud

masukan

Basic Image Processing

Terakhir diperbarui:2024-01-23 17:15:08

    Overview

    This document provides an overview of APIs and SDK code samples related to basic image processing.
    Service
    Feature
    Description
    Image Processing-Basic Services
    Proportional scaling, scaling image to target width and height, and more
    Cut (regular cropping), crop (scaling and cropping), iradius (inscribed circle cropping), and scrop (smart cropping)
    Adaptive rotation and common rotation
    Format conversion, GIF optimization, and progressive display
    Changes the quality of images in JPG and WEBP formats
    Blurs images
    Sharpens images
    Watermarking
    Obtaining image information
    Includes EXIF data
    Performs quick format conversion, scaling, and cropping to generate thumbnails
    

    SDK API References

    For parameters and method description of all APIs in the SDK, please see SDK API Reference.

    Processing an Image upon the Upload

    The following example shows how to automatically process an image when you upload it to COS.
    When the image is uploaded successfully, COS will save both the input and output images. You can later obtain the processing results using a general download request.

    Sample code

    Objective-C
    QCloudPutObjectWatermarkRequest* put = [QCloudPutObjectWatermarkRequest new];
    
    // Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"
    put.object = @"exampleobject";
    // Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    put.bucket = @"examplebucket-1250000000";
    
    put.body = [@"123456789" dataUsingEncoding:NSUTF8StringEncoding];
    QCloudPicOperations * op = [[QCloudPicOperations alloc]init];
    
    // Indicate whether to return information of the original image. `0` (default): no; `1`: yes
    op.is_pic_info = NO;
    QCloudPicOperationRule * rule = [[QCloudPicOperationRule alloc]init];
    
    // Path of processing result file. If the path starts with `/`, the result file is stored in the specified folder. Otherwise, it is stored in the same directory as the input image file.
    rule.fileid = @"test";
    
    // Blind watermark text, which must be URL-safe Base64-encoded. This parameter is required if `type` is set to `3` and does not take effect if `type` is set to `1` or `2`.
    rule.text = @"123"; // The watermark text can only be a string of [a-z, A-Z, 0-9]
    
    // Blind watermark type. Valid values: `1` (semi-blind), `2` (perfectly blind), `3` (text)
    rule.type = QCloudPicOperationRuleText;
    op.rule = @[rule];
    put.picOperations = op;
    [put setFinishBlock:^(id outputObject, NSError *error) {
    
    }];
    [[QCloudCOSXMLService defaultCOSXML] PutWatermarkObject:put];
    Note:
    For the complete sample, go to GitHub.
    Swift
    let put = QCloudPutObjectWatermarkRequest<AnyObject>();
    
    // Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"
    put.object = "exampleobject";
    // Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    
    put.bucket = "examplebucket-1250000000";
    put.body = "123456789".data(using: .utf8)! as NSData;
    let op = QCloudPicOperations.init();
    
    // Indicate whether to return information of the original image. `0` (default): no; `1`: yes
    op.is_pic_info = false;
    
    let rule = QCloudPicOperationRule.init();
    
    // Path of processing result file. If the path starts with `/`, the result file is stored in the specified folder. Otherwise, it is stored in the same directory as the input image file.
    
    rule.fileid = "test";
    
    // Blind watermark text, which must be URL-safe Base64-encoded. This parameter is required if `type` is set to `3` and does not take effect if `type` is set to `1` or `2`.
    rule.text = "123";
    
    // Blind watermark type. Valid values: `1` (semi-blind), `2` (perfectly blind), `3` (text)
    rule.type = .text;
    
    op.rule = [rule];
    put.picOperations = op;
    put.setFinish { (outoutObject, error) in
    
    };
    QCloudCOSXMLService.defaultCOSXML().putWatermarkObject(put);
    Note:
    For the complete sample, go to GitHub.

    Processing In-Cloud Data

    The following example shows how to automatically process an image when you upload it to COS.
    When the image is uploaded successfully, COS will save both the input and output images. You can later obtain the processing results using a general download request.

    Sample code

    Objective-C
    QCloudCICloudDataOperationsRequest* put = [QCloudCICloudDataOperationsRequest new];
    
    // Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"
    put.object = @"exampleobject";
    // Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    put.bucket = @"examplebucket-1250000000";
    
    QCloudPicOperations * op = [[QCloudPicOperations alloc]init];
    
    // Indicate whether to return information of the original image. `0` (default): no; `1`: yes
    op.is_pic_info = NO;
    QCloudPicOperationRule * rule = [[QCloudPicOperationRule alloc]init];
    
    // Path of processing result file. If the path starts with `/`, the result file is stored in the specified folder. Otherwise, it is stored in the same directory as the input image file.
    rule.fileid = @"test";
    
    // Blind watermark text, which must be URL-safe Base64-encoded. This parameter is required if `type` is set to `3` and does not take effect if `type` is set to `1` or `2`.
    rule.text = @"123"; // The watermark text can only be a string of [a-z, A-Z, 0-9]
    
    // Blind watermark type. Valid values: `1` (semi-blind), `2` (perfectly blind), `3` (text)
    rule.type = QCloudPicOperationRuleText;
    op.rule = @[rule];
    put.picOperations = op;
    [put setFinishBlock:^(QCloudPutObjectWatermarkResult *outputObject, NSError *error) {
    
    }];
    [[QCloudCOSXMLService defaultCOSXML] CloudDataOperations:put];
    Note:
    For the complete sample, go to GitHub.
    Swift
    let put = QCloudCICloudDataOperationsRequest<AnyObject>();
    
    // Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"
    put.object = "exampleobject";
    // Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    
    put.bucket = "examplebucket-1250000000";
    let op = QCloudPicOperations.init();
    
    // Indicate whether to return information of the original image. `0` (default): no; `1`: yes
    op.is_pic_info = false;
    
    let rule = QCloudPicOperationRule.init();
    
    // Path of processing result file. If the path starts with `/`, the result file is stored in the specified folder. Otherwise, it is stored in the same directory as the input image file.
    
    rule.fileid = "test";
    
    // Blind watermark text, which must be URL-safe Base64-encoded. This parameter is required if `type` is set to `3` and does not take effect if `type` is set to `1` or `2`.
    rule.text = "123";
    
    // Blind watermark type. Valid values: `1` (semi-blind), `2` (perfectly blind), `3` (text)
    rule.type = .text;
    
    op.rule = [rule];
    put.picOperations = op;
    put.setFinish { (outoutObject, error) in
    
    };
    QCloudCOSXMLService.defaultCOSXML().cloudDataOperations(put);
    Note:
    For the complete sample, go to GitHub.
    Hubungi Kami

    Hubungi tim penjualan atau penasihat bisnis kami untuk membantu bisnis Anda.

    Dukungan Teknis

    Buka tiket jika Anda mencari bantuan lebih lanjut. Tiket kami tersedia 7x24.

    Dukungan Telepon 7x24