简介
本文档提供关于基础图片处理的相关的 API 概览以及 SDK 示例代码。
|
基础图片处理服务 | | 等比缩放、设定目标宽高缩放等多种方式 |
| | 普通裁剪、缩放裁剪、内切圆、人脸智能裁剪 |
| | 自适应旋转、普通旋转 |
| | 格式转换、GIF 格式优化、渐进显示 |
| | 针对 JPG 和 WEBP 图片进行质量变换 |
| | 对图片进行模糊处理 |
| | 对图片进行锐化处理 |
| 添加水印 | |
| 获取图片信息 | |
| | 包括 EXIF 信息 |
| | 快速实现图片格式转换、缩略、剪裁等功能,生成缩略图 |
SDK API 参考
上传时使用图片处理
下面示例展示了如何在上传图片时自动实现图片处理。
图片上传完成后,COS 会存储原始图片和已处理过的图片。后续用户可以通过普通的下载请求获取处理结果。
示例代码
Objective-C
QCloudPutObjectWatermarkRequest* put = [QCloudPutObjectWatermarkRequest new];
put.object = @"exampleobject";
put.bucket = @"examplebucket-1250000000";
put.body = [@"123456789" dataUsingEncoding:NSUTF8StringEncoding];
QCloudPicOperations * op = [[QCloudPicOperations alloc]init];
op.is_pic_info = NO;
QCloudPicOperationRule * rule = [[QCloudPicOperationRule alloc]init];
rule.fileid = @"test";
rule.text = @"123";
rule.type = QCloudPicOperationRuleText;
op.rule = @[rule];
put.picOperations = op;
[put setFinishBlock:^(id outputObject, NSError *error) {
}];
[[QCloudCOSXMLService defaultCOSXML] PutWatermarkObject:put];
Swift
let put = QCloudPutObjectWatermarkRequest<AnyObject>();
put.object = "exampleobject";
put.bucket = "examplebucket-1250000000";
put.body = "123456789".data(using: .utf8)! as NSData;
let op = QCloudPicOperations.init();
op.is_pic_info = false;
let rule = QCloudPicOperationRule.init();
rule.fileid = "test";
rule.text = "123";
rule.type = .text;
op.rule = [rule];
put.picOperations = op;
put.setFinish { (outoutObject, error) in
};
QCloudCOSXMLService.defaultCOSXML().putWatermarkObject(put);
云上数据处理
下面示例展示了如何在上传图片时自动实现图片处理。
图片上传完成后,COS 会存储原始图片和已处理过的图片。后续用户可以通过普通的下载请求获取处理结果。
示例代码
Objective-C
QCloudCICloudDataOperationsRequest* put = [QCloudCICloudDataOperationsRequest new];
put.object = @"exampleobject";
put.bucket = @"examplebucket-1250000000";
QCloudPicOperations * op = [[QCloudPicOperations alloc]init];
op.is_pic_info = NO;
QCloudPicOperationRule * rule = [[QCloudPicOperationRule alloc]init];
rule.fileid = @"test";
rule.text = @"123";
rule.type = QCloudPicOperationRuleText;
op.rule = @[rule];
put.picOperations = op;
[put setFinishBlock:^(QCloudPutObjectWatermarkResult *outputObject, NSError *error) {
}];
[[QCloudCOSXMLService defaultCOSXML] CloudDataOperations:put];
Swift
let put = QCloudCICloudDataOperationsRequest<AnyObject>();
put.object = "exampleobject";
put.bucket = "examplebucket-1250000000";
let op = QCloudPicOperations.init();
op.is_pic_info = false;
let rule = QCloudPicOperationRule.init();
rule.fileid = "test";
rule.text = "123";
rule.type = .text;
op.rule = [rule];
put.picOperations = op;
put.setFinish { (outoutObject, error) in
};
QCloudCOSXMLService.defaultCOSXML().cloudDataOperations(put);
本页内容是否解决了您的问题?