update code
parent
723c28b1c6
commit
c692101bfc
1
pom.xml
1
pom.xml
|
@ -107,7 +107,6 @@
|
|||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>${velocity.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- collections工具类 -->
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
|
|
|
@ -137,7 +137,13 @@
|
|||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-http</artifactId>
|
||||
<version>5.3.3</version>
|
||||
<version>5.8.16</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-core</artifactId>
|
||||
<version>5.8.16</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -3,7 +3,12 @@ package com.ruoyi.common.utils.file;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.ruoyi.common.config.RuoYiConfig;
|
||||
|
@ -114,9 +119,42 @@ public class FileUploadUtils
|
|||
|
||||
String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
|
||||
file.transferTo(Paths.get(absPath));
|
||||
makeMiniImage(absPath);
|
||||
return getPathFileName(baseDir, fileName);
|
||||
}
|
||||
|
||||
private static void makeMiniImage(String absPath) {
|
||||
try {
|
||||
String ext = FileUtils.getFileExt(absPath).toLowerCase();
|
||||
String exts = Arrays.toString(new String[]{"jpg", "jpeg", "png", "bmp"});
|
||||
if (exts.contains(ext)) {
|
||||
if (new File(absPath).exists()) {
|
||||
int w = ImgUtil.read(FileUtil.file(absPath)).getWidth();
|
||||
if(w>2000) {
|
||||
ImgUtil.scale(FileUtil.file(absPath),
|
||||
FileUtil.file(absPath), (float) (2000.0 / w));
|
||||
}
|
||||
ImgUtil.scale(FileUtil.file(absPath),
|
||||
FileUtil.file(absPath + ".min.jpg"), (float) (300.0 / w));
|
||||
}
|
||||
}
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
List<File> list= FileUtil.loopFiles("D:/hahaprj/tmp");
|
||||
for(File f :list){
|
||||
System.out.println(f.getAbsolutePath());
|
||||
makeMiniImage(f.getAbsolutePath());
|
||||
}
|
||||
|
||||
//String f="D:\\hahaprj\\tmp\\2023\\07\\30\\840_20230730152314A005.jpg";
|
||||
//makeMiniImage(f);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编码文件名
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue