Search in sources :

Example 1 with ImageProcessRequest

use of com.qcloud.cos.model.ciModel.common.ImageProcessRequest in project cos-java-sdk-v5 by tencentyun.

the class ImagePersistenceDemo method persistenceImagePost.

public static void persistenceImagePost(COSClient cosClient) {
    String bucketName = "examplebucket-1250000000";
    String key = "test.jpg";
    ImageProcessRequest imageReq = new ImageProcessRequest(bucketName, key);
    PicOperations picOperations = new PicOperations();
    picOperations.setIsPicInfo(1);
    List<PicOperations.Rule> ruleList = new LinkedList<>();
    PicOperations.Rule rule1 = new PicOperations.Rule();
    rule1.setBucket(bucketName);
    rule1.setFileId("test-1.jpg");
    rule1.setRule("imageMogr2/rotate/90");
    ruleList.add(rule1);
    PicOperations.Rule rule2 = new PicOperations.Rule();
    rule2.setBucket(bucketName);
    rule2.setFileId("test-2.jpg");
    rule2.setRule("imageMogr2/rotate/180");
    ruleList.add(rule2);
    picOperations.setRules(ruleList);
    imageReq.setPicOperations(picOperations);
    try {
        CIUploadResult ciUploadResult = cosClient.processImage(imageReq);
        System.out.println(ciUploadResult.getOriginalInfo().getEtag());
        for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
            System.out.println(ciObject.getLocation());
            System.out.println(ciObject.getEtag());
        }
    } catch (CosServiceException e) {
        e.printStackTrace();
    } catch (CosClientException e) {
        e.printStackTrace();
    }
}
Also used : CosServiceException(com.qcloud.cos.exception.CosServiceException) CosClientException(com.qcloud.cos.exception.CosClientException) PicOperations(com.qcloud.cos.model.ciModel.persistence.PicOperations) CIUploadResult(com.qcloud.cos.model.ciModel.persistence.CIUploadResult) ImageProcessRequest(com.qcloud.cos.model.ciModel.common.ImageProcessRequest) LinkedList(java.util.LinkedList) CIObject(com.qcloud.cos.model.ciModel.persistence.CIObject)

Example 2 with ImageProcessRequest

use of com.qcloud.cos.model.ciModel.common.ImageProcessRequest in project cos-java-sdk-v5 by tencentyun.

the class BlindWatermarkDemo method addBlindWatermarkToExistImage.

public static void addBlindWatermarkToExistImage(COSClient cosClient) {
    // bucket名需包含appid
    // api 请参考:https://cloud.tencent.com/document/product/436/46782
    String bucketName = "examplebucket-1250000000";
    String key = "image/dog.jpg";
    ImageProcessRequest imageProcessRequest = new ImageProcessRequest(bucketName, key);
    PicOperations picOperations = new PicOperations();
    picOperations.setIsPicInfo(1);
    List<PicOperations.Rule> ruleList = new LinkedList<>();
    PicOperations.Rule rule = new PicOperations.Rule();
    rule.setBucket(bucketName);
    rule.setFileId("/image/result/dog.jpg");
    // 使用盲水印功能,水印图的宽高不得超过原图的1/8
    rule.setRule("watermark/3/type/2/image/aHR0cDovL2V4YW1wbGVidWNrZXQtMTI1MDAwMDAwMC5jb3MuYXAtZ3Vhbmd6aG91Lm15cWNsb3VkLmNvbS9zaHVpeWluLnBuZw==");
    ruleList.add(rule);
    picOperations.setRules(ruleList);
    imageProcessRequest.setPicOperations(picOperations);
    try {
        CIUploadResult ciUploadResult = cosClient.processImage(imageProcessRequest);
        System.out.println(ciUploadResult.getOriginalInfo().getEtag());
        for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
            System.out.println(ciObject.getLocation());
        }
    } catch (CosServiceException e) {
        e.printStackTrace();
    } catch (CosClientException e) {
        e.printStackTrace();
    }
}
Also used : CosServiceException(com.qcloud.cos.exception.CosServiceException) CosClientException(com.qcloud.cos.exception.CosClientException) PicOperations(com.qcloud.cos.model.ciModel.persistence.PicOperations) CIUploadResult(com.qcloud.cos.model.ciModel.persistence.CIUploadResult) ImageProcessRequest(com.qcloud.cos.model.ciModel.common.ImageProcessRequest) LinkedList(java.util.LinkedList) CIObject(com.qcloud.cos.model.ciModel.persistence.CIObject)

Example 3 with ImageProcessRequest

use of com.qcloud.cos.model.ciModel.common.ImageProcessRequest in project cos-java-sdk-v5 by tencentyun.

the class BlindWatermarkDemo method extractBlindWatermarkFromExistImage.

public static void extractBlindWatermarkFromExistImage(COSClient cosClient) {
    // bucket名需包含appid
    // api 请参考:https://cloud.tencent.com/document/product/436/46782
    String bucketName = "examplebucket-1250000000";
    String key = "image/result/dog.jpg";
    ImageProcessRequest imageProcessRequest = new ImageProcessRequest(bucketName, key);
    PicOperations picOperations = new PicOperations();
    picOperations.setIsPicInfo(1);
    List<PicOperations.Rule> ruleList = new LinkedList<>();
    PicOperations.Rule rule = new PicOperations.Rule();
    rule.setBucket(bucketName);
    rule.setFileId("/image/result/extract-shuiyin.jpg");
    // 抽取盲水印
    rule.setRule("watermark/4/type/2/image/aHR0cDovL2V4YW1wbGVidWNrZXQtMTI1MDAwMDAwMC5jb3MuYXAtZ3Vhbmd6aG91Lm15cWNsb3VkLmNvbS9zaHVpeWluLnBuZw==");
    ruleList.add(rule);
    picOperations.setRules(ruleList);
    imageProcessRequest.setPicOperations(picOperations);
    try {
        CIUploadResult ciUploadResult = cosClient.processImage(imageProcessRequest);
        System.out.println(ciUploadResult.getOriginalInfo().getEtag());
        for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
            System.out.println(ciObject.getLocation());
        }
    } catch (CosServiceException e) {
        e.printStackTrace();
    } catch (CosClientException e) {
        e.printStackTrace();
    }
}
Also used : CosServiceException(com.qcloud.cos.exception.CosServiceException) CosClientException(com.qcloud.cos.exception.CosClientException) PicOperations(com.qcloud.cos.model.ciModel.persistence.PicOperations) CIUploadResult(com.qcloud.cos.model.ciModel.persistence.CIUploadResult) ImageProcessRequest(com.qcloud.cos.model.ciModel.common.ImageProcessRequest) LinkedList(java.util.LinkedList) CIObject(com.qcloud.cos.model.ciModel.persistence.CIObject)

Aggregations

CosClientException (com.qcloud.cos.exception.CosClientException)3 CosServiceException (com.qcloud.cos.exception.CosServiceException)3 ImageProcessRequest (com.qcloud.cos.model.ciModel.common.ImageProcessRequest)3 CIObject (com.qcloud.cos.model.ciModel.persistence.CIObject)3 CIUploadResult (com.qcloud.cos.model.ciModel.persistence.CIUploadResult)3 PicOperations (com.qcloud.cos.model.ciModel.persistence.PicOperations)3 LinkedList (java.util.LinkedList)3