|
@@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.List;
|
|
@@ -49,7 +50,7 @@ public class ProduceServiceImpl implements ProducerService {
|
|
|
Long userId = JwtUtil.getUserId(request.getHeader("token"));
|
|
|
long start = System.currentTimeMillis();
|
|
|
// 全景图只支持jpg图片格式
|
|
|
- checkImgType(file);
|
|
|
+ checkImg(file);
|
|
|
|
|
|
long kb = fileUtils.getSize(file, "kB");
|
|
|
BaseRuntimeException.isHas((kb/1024) >=120, null, "全景图文件不能超过120MB");
|
|
@@ -103,7 +104,11 @@ public class ProduceServiceImpl implements ProducerService {
|
|
|
return Result.success(fodderMapper.selectList(wrapper));
|
|
|
}
|
|
|
|
|
|
- private void checkImgType(MultipartFile file){
|
|
|
+ /**
|
|
|
+ * 检查图片类型
|
|
|
+ * @param file
|
|
|
+ */
|
|
|
+ private void checkImg(MultipartFile file){
|
|
|
// 次方法可以读取到图片内部结构, 可以检验非全景图
|
|
|
try {
|
|
|
String imgType = FileTypeUtil.getType(file.getInputStream());
|
|
@@ -113,8 +118,16 @@ public class ProduceServiceImpl implements ProducerService {
|
|
|
boolean jpg = imgType.equalsIgnoreCase("jpg");
|
|
|
BaseRuntimeException.isHas(!jpg, null, msg);
|
|
|
|
|
|
+ // 检查2:1图片
|
|
|
+ BufferedImage read = cn.hutool.core.img.ImgUtil.read(file.getInputStream());
|
|
|
+ int width = read.getWidth();
|
|
|
+ int height = read.getHeight();
|
|
|
+ BaseRuntimeException.isHas(!(width/height == 2), null, "非2:1图片");
|
|
|
+
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|