This document provides an overview of APIs and SDK code samples related to basic image processing.
Service | Feature | Description |
---|---|---|
Image Processing-Basic Services | Scaling | Proportional scaling, scaling image to target width and height, and more |
Cropping | Cut (regular cropping), crop (scaling and cropping), iradius (inscribed circle cropping), and scrop (smart cropping) | |
Rotation | Adaptive rotation and common rotation | |
Format conversion | Format conversion, GIF optimization, and progressive display | |
Quality conversion | Changes the quality of images in JPG and WEBP formats | |
Gaussian blurring | Blurs images | |
Sharpening | Sharpens images | |
Watermarking | Image watermarks, text watermarks | |
Obtaining image information | Basic information, EXIF data, average hue | |
Removing metadata | Includes EXIF data | |
Quick thumbnail template | Performs quick format conversion, scaling, and cropping to generate thumbnails |
For parameters and method description of all APIs in the SDK, please see SDK API Reference.
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.
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.intl.cloud.tencent.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.intl.cloud.tencent.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.
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.
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.intl.cloud.tencent.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.intl.cloud.tencent.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.
Was this page helpful?