注意
- 暂时不支持从 dora 数据处理直接调该接口,只支持从 kodo 存储调用。即 cdn 域名不可开通图片瘦身
调用形式
资源
http://i.iamlj.com/19-08-12/123936.png
处理参数
watermark/6/method/encode/text/aGVsbG8gcWluaXU=
新图
http://i.iamlj.com/19-08-12/123936-watermark-qiniu.png
请求查询
http://api.qiniu.com/status/get/prefop?id=z0.0A22344225B94C93025D536035EC1E3C
加密结果图
https://i.iamlj.com/19-08-12/123936-watermark-qiniu.png
加密结果图对比原图,得出加密参数图
http://7xlv47.com0.z0.glb.clouddn.com/upload.jpg
Pfop 请求生成新图
Java 编码代码参考
package me.lj.qiniu.dora;import com.qiniu.common.QiniuException;
import com.qiniu.common.Zone;
import com.qiniu.processing.OperationManager;
import com.qiniu.storage.Configuration;
import com.qiniu.util.Auth;
import com.qiniu.util.UrlSafeBase64;
import me.lj.qiniu.config.Config;import java.io.IOException;/*** 图片另存为*/
public class PfopsImageWatermark {public static void main(String args[]) throws IOException {//设置好账号的ACCESS_KEY和SECRET_KEYString ACCESS_KEY = Config.ACCESS_KEY;String SECRET_KEY = Config.SECRET_KEY;//资源所在空间String bucketname = "image";String key = "19-08-12/123936.png";//上传后的文件名String newKey = "19-08-12/123936-watermark-qiniu.png";//设置转码操作参数String fops = "watermark/6/method/encode/text/cWluaXU=";//设置转码的队列String pipeline = "12349";//可以对转码后的文件进行使用saveas参数自定义命 名,当然也可以不指定文件会默认命名并保存在当前空间。String urlbase64 = UrlSafeBase64.encodeToString(bucketname + ":" + newKey);String pfops = fops + "|saveas/" + urlbase64;//密钥配置Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);//第二种方式: 自动识别要上传的空间(bucket)的存储区域是华东、华北、华南。Zone z = Zone.autoZone();Configuration c = new Configuration(z);OperationManager operationManager = new OperationManager(auth, c);String id = null;try {id = operationManager.pfop(bucketname, key, pfops, pipeline, true);} catch (QiniuException e) {e.printStackTrace();}System.out.println(id);}}
Java 解码代码参考
/*** 图片另存为*/
public class PfopsImageWatermarkDecode {public static void main(String args[]) throws IOException {//设置好账号的ACCESS_KEY和SECRET_KEYString ACCESS_KEY = Config.ACCESS_KEY;String SECRET_KEY = Config.SECRET_KEY;//资源所在空间String bucketname = "image";String originkey = "19-08-12/123936.png";String key = "19-08-12/123936-watermark-qiniu.png";//上传后的文件名String newKey = "19-08-12/123936-watermark-compare.png";//设置转码操作参数String fops = "watermark/6/method/decode/orignal/"+UrlSafeBase64.encodeToString(originkey);;//设置转码的队列String pipeline = "12349";//可以对转码后的文件进行使用saveas参数自定义命 名,当然也可以不指定文件会默认命名并保存在当前空间。String urlbase64 = UrlSafeBase64.encodeToString(bucketname + ":" + newKey);String pfops = fops + "|saveas/" + urlbase64;//密钥配置Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);//第二种方式: 自动识别要上传的空间(bucket)的存储区域是华东、华北、华南。Zone z = Zone.autoZone();Configuration c = new Configuration(z);OperationManager operationManager = new OperationManager(auth, c);String id = null;try {id = operationManager.pfop(bucketname, key, pfops, pipeline, true);} catch (QiniuException e) {e.printStackTrace();}System.out.println(id);}}
解码结果图
参考
盲水印处理