init
This commit is contained in:
41
ruoyi-cai/src/main/java/com/ruoyi/cai/util/CaiFileUtils.java
Normal file
41
ruoyi-cai/src/main/java/com/ruoyi/cai/util/CaiFileUtils.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.ruoyi.cai.util;
|
||||
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.net.URL;
|
||||
|
||||
@Slf4j
|
||||
public class CaiFileUtils {
|
||||
|
||||
@Data
|
||||
public static class FileSize {
|
||||
private int width = 500;
|
||||
private int height = 500;
|
||||
private String suffix;
|
||||
}
|
||||
|
||||
private static String BASE_URL = "https://nono-1257812345.cos.ap-shanghai.myqcloud.com/";
|
||||
|
||||
public static FileSize getFileSize(String url){
|
||||
FileSize fileSize = new FileSize();
|
||||
String suffix = StringUtils.substring(url, url.lastIndexOf("."), url.length());
|
||||
fileSize.setSuffix(suffix);
|
||||
try {
|
||||
URL imageUrl = new URL(BASE_URL+url); // 替换为实际的图片 URL
|
||||
BufferedImage image = ImageIO.read(imageUrl);
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
fileSize.setWidth(width);
|
||||
fileSize.setHeight(height);
|
||||
return fileSize;
|
||||
}catch (Exception e){
|
||||
log.error("获取文件图片大小失败",e);
|
||||
}
|
||||
return new FileSize();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user