🆕 #1685 小程序增加图像处理相关接口

This commit is contained in:
Binary Wang
2020-08-08 17:14:09 +08:00
parent 542b633c70
commit 14dfe30bf6
12 changed files with 287 additions and 114 deletions

View File

@ -0,0 +1,121 @@
package me.chanjar.weixin.common.api;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.bean.imgproc.WxImgProcAiCropResult;
import me.chanjar.weixin.common.bean.imgproc.WxImgProcQrCodeResult;
import me.chanjar.weixin.common.bean.imgproc.WxImgProcSuperResolutionResult;
import java.io.File;
/**
* 多项图像处理能力相关的API.
* https://developers.weixin.qq.com/doc/offiaccount/Intelligent_Interface/Img_Proc.html
*
* @author Theo Nie
*/
public interface WxImgProcService {
/**
* 二维码/条码识别接口
* 说明:
* 1.图片支持使用img参数实时上传也支持使用img_url参数传送图片地址由微信后台下载图片进行识别
* 2.文件大小限制小于2M
* 3.支持条码、二维码、DataMatrix和PDF417的识别。
* 4.二维码、DataMatrix会返回位置坐标条码和PDF417暂不返回位置坐标。
*
* @param imgUrl 图片url地址
* @return WxMpImgProcQrCodeResult
* @throws WxErrorException .
*/
WxImgProcQrCodeResult qrCode(String imgUrl) throws WxErrorException;
/**
* 二维码/条码识别接口
* 说明:
* 1.图片支持使用img参数实时上传也支持使用img_url参数传送图片地址由微信后台下载图片进行识别
* 2.文件大小限制小于2M
* 3.支持条码、二维码、DataMatrix和PDF417的识别。
* 4.二维码、DataMatrix会返回位置坐标条码和PDF417暂不返回位置坐标。
*
* @param imgFile 图片文件对象
* @return WxMpImgProcQrCodeResult
* @throws WxErrorException .
*/
WxImgProcQrCodeResult qrCode(File imgFile) throws WxErrorException;
/**
* 图片高清化接口
* 说明:
* 1.图片支持使用img参数实时上传也支持使用img_url参数传送图片地址由微信后台下载图片进行识别
* 2.文件大小限制小于2M
* 3.目前支持将图片超分辨率高清化2倍即生成图片分辨率为原图2倍大小
* 返回的media_id有效期为3天期间可以通过“获取临时素材”接口获取图片二进制
*
* @param imgUrl 图片url地址
* @return WxMpImgProcSuperResolutionResult
* @throws WxErrorException .
*/
WxImgProcSuperResolutionResult superResolution(String imgUrl) throws WxErrorException;
/**
* 图片高清化接口
* 说明:
* 1.图片支持使用img参数实时上传也支持使用img_url参数传送图片地址由微信后台下载图片进行识别
* 2.文件大小限制小于2M
* 3.目前支持将图片超分辨率高清化2倍即生成图片分辨率为原图2倍大小
* 返回的media_id有效期为3天期间可以通过“获取临时素材”接口获取图片二进制
*
* @param imgFile 图片文件对象
* @return WxMpImgProcSuperResolutionResult
* @throws WxErrorException .
*/
WxImgProcSuperResolutionResult superResolution(File imgFile) throws WxErrorException;
/**
* 图片智能裁剪接口
* 说明:
* 1.图片支持使用img参数实时上传也支持使用img_url参数传送图片地址由微信后台下载图片进行识别
* 2.文件大小限制小于2M
* 3.该接口默认使用最佳宽高比
* @param imgUrl 图片url地址
* @return WxMpImgProcAiCropResult
* @throws WxErrorException .
*/
WxImgProcAiCropResult aiCrop(String imgUrl) throws WxErrorException;
/**
* 图片智能裁剪接口
* 说明:
* 1.图片支持使用img参数实时上传也支持使用img_url参数传送图片地址由微信后台下载图片进行识别
* 2.文件大小限制小于2M
* @param imgUrl 图片url地址
* @param ratios 宽高比最多支持5个请以英文逗号分隔
* @return WxMpImgProcAiCropResult
* @throws WxErrorException .
*/
WxImgProcAiCropResult aiCrop(String imgUrl, String ratios) throws WxErrorException;
/**
* 图片智能裁剪接口
* 说明:
* 1.图片支持使用img参数实时上传也支持使用img_url参数传送图片地址由微信后台下载图片进行识别
* 2.文件大小限制小于2M
* 3.该接口默认使用最佳宽高比
* @param imgFile 图片文件对象
* @return WxMpImgProcAiCropResult
* @throws WxErrorException .
*/
WxImgProcAiCropResult aiCrop(File imgFile) throws WxErrorException;
/**
* 图片智能裁剪接口
* 说明:
* 1.图片支持使用img参数实时上传也支持使用img_url参数传送图片地址由微信后台下载图片进行识别
* 2.文件大小限制小于2M
* @param imgFile 图片文件对象
* @param ratios 宽高比最多支持5个请以英文逗号分隔
* @return WxMpImgProcAiCropResult
* @throws WxErrorException .
*/
WxImgProcAiCropResult aiCrop(File imgFile, String ratios) throws WxErrorException;
}

View File

@ -0,0 +1,69 @@
package me.chanjar.weixin.common.bean.imgproc;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import java.io.Serializable;
import java.util.List;
/**
* @author Theo Nie
*/
@Data
public class WxImgProcAiCropResult implements Serializable {
private static final long serialVersionUID = -6470673963772979463L;
@SerializedName("img_size")
private ImgSize imgSize;
@SerializedName("results")
private List<Results> results;
@Override
public String toString() {
return WxGsonBuilder.create().toJson(this);
}
public static WxImgProcAiCropResult fromJson(String json) {
return WxGsonBuilder.create().fromJson(json, WxImgProcAiCropResult.class);
}
@Data
public static class ImgSize implements Serializable {
private static final long serialVersionUID = -6470673963772979463L;
@SerializedName("w")
private int w;
@SerializedName("h")
private int h;
@Override
public String toString() {
return WxGsonBuilder.create().toJson(this);
}
}
@Data
public static class Results implements Serializable {
private static final long serialVersionUID = -6470673963772979463L;
@SerializedName("crop_left")
private int cropLeft;
@SerializedName("crop_top")
private int cropTop;
@SerializedName("crop_right")
private int cropRight;
@SerializedName("crop_bottom")
private int cropBottom;
@Override
public String toString() {
return WxGsonBuilder.create().toJson(this);
}
}
}

View File

@ -0,0 +1,103 @@
package me.chanjar.weixin.common.bean.imgproc;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import java.io.Serializable;
import java.util.List;
/**
* 二维码/条码识别返回结果
*
* @author Theo Nie
*/
@Data
public class WxImgProcQrCodeResult implements Serializable {
private static final long serialVersionUID = -1194154790100866123L;
@SerializedName("img_size")
private ImgSize imgSize;
@SerializedName("code_results")
private List<CodeResults> codeResults;
@Data
public static class ImgSize implements Serializable {
private static final long serialVersionUID = -8847603245514017839L;
@SerializedName("w")
private int w;
@SerializedName("h")
private int h;
@Override
public String toString() {
return WxGsonBuilder.create().toJson(this);
}
}
@Data
public static class CodeResults implements Serializable {
private static final long serialVersionUID = -6138135951229076759L;
@SerializedName("type_name")
private String typeName;
@SerializedName("data")
private String data;
@SerializedName("pos")
private Pos pos;
@Override
public String toString() {
return WxGsonBuilder.create().toJson(this);
}
@Data
public static class Pos implements Serializable {
private static final long serialVersionUID = 7754894061212819602L;
@SerializedName("left_top")
private Coordinate leftTop;
@SerializedName("right_top")
private Coordinate rightTop;
@SerializedName("right_bottom")
private Coordinate rightBottom;
@SerializedName("left_bottom")
private Coordinate leftBottom;
@Override
public String toString() {
return WxGsonBuilder.create().toJson(this);
}
@Data
public static class Coordinate implements Serializable {
private static final long serialVersionUID = 8930443668927359677L;
@SerializedName("x")
private int x;
@SerializedName("y")
private int y;
@Override
public String toString() {
return WxGsonBuilder.create().toJson(this);
}
}
}
}
public static WxImgProcQrCodeResult fromJson(String json) {
return WxGsonBuilder.create().fromJson(json, WxImgProcQrCodeResult.class);
}
@Override
public String toString() {
return WxGsonBuilder.create().toJson(this);
}
}

View File

@ -0,0 +1,28 @@
package me.chanjar.weixin.common.bean.imgproc;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import java.io.Serializable;
/**
* 图片高清化返回结果
* @author Theo Nie
*/
@Data
public class WxImgProcSuperResolutionResult implements Serializable {
private static final long serialVersionUID = 8007440280170407021L;
@SerializedName("media_id")
private String mediaId;
@Override
public String toString() {
return WxGsonBuilder.create().toJson(this);
}
public static WxImgProcSuperResolutionResult fromJson(String json) {
return WxGsonBuilder.create().fromJson(json, WxImgProcSuperResolutionResult.class);
}
}