Commit 5471d7a6 by 王祖波

图片压缩

parent b921b18d
......@@ -243,10 +243,11 @@ public class MaterialServiceImpl implements MaterialService {
Integer width = jsonObject.getInteger("width");
Integer height = jsonObject.getInteger("height");
Integer size = jsonObject.getInteger("size");
String extensions = url.substring(url.lastIndexOf(".") + 1);
//朋友圈类型图片,长边不超过10800像素,短边不超过1080像素
//图片宽高超过限制 或 大小大于2m 处理图片
if (size / 1000 > 2000 || width > 1080 || height > 10800) {
url+= "?imageView2/2/w/1080/h/10800" ;
if (size / 1000 > 2000 || width > 1080 || height > 10800 || Objects.equals(extensions,"png")) {
url+= "?imageView2/2/w/1080/h/10800/format/jpg" ;
}
logger.info("url={}",url);
}
......@@ -272,21 +273,22 @@ public class MaterialServiceImpl implements MaterialService {
public static void main(String[] args) {
String url = "https://platform-1251519181.cos.ap-shanghai.myqcloud.com/image/jhdm/common-fbcae3533d414bf8baac917df600b20e.png";
Map<String, Object> map = HttpClient.getHttpByGet(url + "?imageInfo");
String response = (String) map.get("response");
if (StringUtils.isBlank(response)) {
throw new RuntimeException();
}
JSONObject jsonObject = null;
jsonObject = JSONObject.parseObject(response);
Integer width = jsonObject.getInteger("width");
Integer height = jsonObject.getInteger("height");
Integer size = jsonObject.getInteger("size");
//图片宽高超过限制 或 大小大于2m 处理图片
if (size / 1000 > 2000 || width > 1440 || height > 1080) {
url+= "?imageView2/2/w/1440/h/1080" ;
}
logger.info("url={}",url);
// Map<String, Object> map = HttpClient.getHttpByGet(url + "?imageInfo");
// String response = (String) map.get("response");
// if (StringUtils.isBlank(response)) {
// throw new RuntimeException();
// }
// JSONObject jsonObject = null;
// jsonObject = JSONObject.parseObject(response);
// Integer width = jsonObject.getInteger("width");
// Integer height = jsonObject.getInteger("height");
// Integer size = jsonObject.getInteger("size");
// //图片宽高超过限制 或 大小大于2m 处理图片
// if (size / 1000 > 2000 || width > 1440 || height > 1080) {
// url+= "?imageView2/2/w/1440/h/1080" ;
// }
String substring = url.substring(url.lastIndexOf(".") + 1);
logger.info("url={}",substring);
}
public List<String> getImageMediaId(String wxEnterpriseId, List<ContentMaterialDTO> imageList, int mediaType) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment