API | Description |
Processes images persistently. |
CosResult PutImage(const PutImageByFileReq& request, PutImageByFileResp* response);
qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);std::string bucket_name = "examplebucket-1250000000";PutImageByFileReq req(bucket_name, object_name, local_file);PutImageByFileResp resp;PicOperation pic_operation;PicRules rule;// 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.rule.fileid = "/" + object_name + "_sharpen";// Sharpening parameterrule.rule = "imageMogr2/sharpen/70";pic_operation.AddRule(rule);rule.fileid = "/" + object_name + "_rotate";// Rotation parameterrule.rule = "imageMogr2/rotate/90";pic_operation.AddRule(rule);CosResult result = cos.PutImage(req, &resp);if (result.IsSucc()) {// The call is successful. You can call the `resp` member functions to get the return content.std::cout << "ProcessResult: " << resp.GetUploadResult().to_string() << std::endl;} else {// The call failed. You can call the `result` member functions to get the error information.}
Parameter | Description | Type | Required |
req | PutImage operation request. | PutImageByFileReq | Yes |
resp | PutImage operation response. | PutImageByFileResp | Yes |
req
involves the following structures:struct PicRules {std::string 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.std::string 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.std::string rule; // Processing parameters. For more information, see the COS image processing API. To process an image with 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`.};class PicOperation {public:PicOperation() : is_pic_info(true) {}virtual ~PicOperation() {}void AddRule(const PicRules& rule) { rules.push_back(rule); }void TurnOffPicInfo() { is_pic_info = false; }private:boolis_pic_info; // Whether to return the input image information. Valid values: 0 (no), 1 (yes). Default value: 0.std::vector<PicRules> 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.};
resp
involves the following structures:struct CodeLocation {std::vector<std::string> points; // QR code coordinates};struct QRcodeInfo {std::string code_url; // QR code content. Content may not be recognized.CodeLocation code_location; // Location coordinates of the QR code recognized in the image};struct Object {std::string key; // Filenamestd::string location; // Image pathstd::string format; // Image formatint width; // Image widthint height; // Image heightint size; // Image sizeint quality; // Image qualitystd::string etag; // `ETag` of the processing result imageint code_status; // Whether QR codes are recognized. 0: no; 1: yes.int watermark_status; // When `type`// is 2, this field will be returned to indicate the confidence of the extracted blind watermark.// Value range: 0–100. If the value is above 75, there is a confirmed blind watermark. If the value is between 60 and 75, there is a suspected blind watermark. If the value is below 60, no blind watermark is extracted.std::vector<QRcodeInfo> qr_code_info; // Recognized QR code. There may be multiple ones.};struct ProcessResults {std::vector<Object> objects; // There may be multiple objects};struct ImageInfo {std::string format; // Formatint width; // Image widthint height; // Image heightint quality; // Image qualitystd::string ave; // Image average hueint orientation; // Image rotation angle};struct UploadResult {OriginalInfo original_info; // Input image informationProcessResults process_result; // Image processing result};
CosResult CloudImageProcess(const CloudImageProcessReq& request, CloudImageProcessResp* response);
qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);std::string bucket_name = "examplebucket-1250000000";CloudImageProcessReq req(bucket_name, object_name);CloudImageProcessResp resp;PicOperation pic_operation;PicRules rule;// 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.rule.fileid = "/" + object_name + "_thumbnail";// Scaling parameterrule.rule = "imageMogr2/thumbnail/!30p";pic_operation.AddRule(rule);rule.fileid = "/" + object_name + "_cut";// Cropping parameterrule.rule = "imageMogr2/cut/300x300";pic_operation.AddRule(rule);req.SetPicOperation(pic_operation);CosResult result = cos.CloudImageProcess(req, &resp);if (result.IsSucc()) {// The call is successful. You can call the `resp` member functions to get the return content.} else {// The call failed. You can call the `result` member functions to get the error information.}
Parameter | Description | Type | Required |
req | PutImage operation request. | PutImageByFileReq | Yes |
resp | PutImage operation response. | PutImageByFileResp | Yes |
Was this page helpful?