Commit 0f92aa9f authored by 周健威's avatar 周健威

修改代码

parent 64852da0
package com.upyuns.platform.rs.website.controller.web;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
......@@ -83,36 +84,37 @@ public class GainDataController extends BaseController<GainDataBiz,GainData> {
gainData.setIsDel(SYS_FALSE);
List<GainData> gainData1 = baseBiz.selectAll(gainData);
for(GainData gainData2 : gainData1) {
String path = gainData2.getPictureUrl().replaceAll("https://gdxm.upyuns.com/image","/sdbdata/www/gdweb_resources/image");
path = path.replaceAll("https://zzrsmgmt.upyuns.com/image","/sdbdata/www/gdweb_resources/image");
String path250 = path + "_250";
if(!FileUtil.exist(path250)) {
//生成250
BufferedImage originalImage = ImageIO.read(new File(path));
int originalWidth = originalImage.getWidth();
int originalHeight = originalImage.getHeight();
double scaleFactor = 1.0;
if(StrUtil.isNotBlank(gainData2.getPictureUrl())) {
String path = gainData2.getPictureUrl().replaceAll("https://gdxm.upyuns.com/image","/sdbdata/www/gdweb_resources/image");
path = path.replaceAll("https://zzrsmgmt.upyuns.com/image","/sdbdata/www/gdweb_resources/image");
String path250 = path + "_250";
if(!FileUtil.exist(path250)) {
//生成250
BufferedImage originalImage = ImageIO.read(new File(path));
int originalWidth = originalImage.getWidth();
int originalHeight = originalImage.getHeight();
double scaleFactor = 1.0;
if (originalWidth > originalHeight) {
scaleFactor = (double) 500 / originalWidth;
} else {
scaleFactor = (double) 500 / originalHeight;
}
if (originalWidth > originalHeight) {
scaleFactor = (double) 500 / originalWidth;
} else {
scaleFactor = (double) 500 / originalHeight;
}
int newWidth = (int) (originalWidth * scaleFactor);
int newHeight = (int) (originalHeight * scaleFactor);
int newWidth = (int) (originalWidth * scaleFactor);
int newHeight = (int) (originalHeight * scaleFactor);
BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, originalImage.getType());
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, newWidth, newHeight, null);
g.dispose();
BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, originalImage.getType());
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, newWidth, newHeight, null);
g.dispose();
// 保存压缩后的图片
String compressedFilePath = path250;
String lastFormat = path.substring(path.lastIndexOf("."));
ImageIO.write(resizedImage, lastFormat.substring(1, lastFormat.length()), new File(compressedFilePath));
// 保存压缩后的图片
String compressedFilePath = path250;
String lastFormat = path.substring(path.lastIndexOf("."));
ImageIO.write(resizedImage, lastFormat.substring(1, lastFormat.length()), new File(compressedFilePath));
}
}
}
return ObjectRestResponse.succ();
}
......
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