|
@@ -243,12 +243,12 @@ public class FileUploadController extends BaseApiController {
|
|
|
try {
|
|
|
QcloudFileUtils.putStream(file.getInputStream(), name, bucketName, mimeType );
|
|
|
BufferedImage bufferedImage = ImageIO.read(file.getInputStream());
|
|
|
- Builder<BufferedImage> builder = Thumbnails.of(bufferedImage);
|
|
|
+// Builder<BufferedImage> builder = Thumbnails.of(bufferedImage);
|
|
|
|
|
|
|
|
|
int pWidth = bufferedImage.getWidth();
|
|
|
int pHeight = bufferedImage.getHeight();
|
|
|
- builder.size(pWidth, pHeight);
|
|
|
+// builder.size(pWidth, pHeight);
|
|
|
double accuracy = CompressUtil.getAccuracy(file.getSize()/1024);
|
|
|
LogUtil.info(logger, "原始文件长:{0},大小:{1},contentType:{2}", pWidth, file.getSize()/1024, mimeType);
|
|
|
|
|
@@ -259,32 +259,37 @@ public class FileUploadController extends BaseApiController {
|
|
|
}
|
|
|
String thumbName = name +"_s";
|
|
|
String outFilePath = filePath+"/thumb/"+thumbName+"."+mimeType.substring(mimeType.lastIndexOf("/")+1);
|
|
|
- builder.toFile(outFilePath);
|
|
|
+// builder.toFile(outFilePath);
|
|
|
|
|
|
// 压缩图片
|
|
|
if (pWidth > 500) {
|
|
|
float scale = 500f / pWidth;
|
|
|
if ("image/png".equals(file.getContentType())) {
|
|
|
- Thumbnails.of(outFilePath).scale(scale > 0.5 ? 0.5 : scale).outputQuality(0.8)
|
|
|
+ Thumbnails.of(bufferedImage).scale(scale > 0.5 ? 0.5 : scale).outputQuality(0.8)
|
|
|
.imageType(BufferedImage.TYPE_INT_ARGB).outputFormat("png")
|
|
|
.toFile(outFilePath);
|
|
|
} else {
|
|
|
- Thumbnails.of(outFilePath).scale(scale).outputQuality(0.8).toFile(outFilePath);
|
|
|
+ Thumbnails.of(bufferedImage).scale(scale).outputQuality(0.8).toFile(outFilePath);
|
|
|
}
|
|
|
}else {
|
|
|
if ("image/png".equals(file.getContentType())) {
|
|
|
- Thumbnails.of(outFilePath).scale(0.5).outputQuality(0.8)
|
|
|
+ Thumbnails.of(bufferedImage).scale(0.5).outputQuality(0.8)
|
|
|
.imageType(BufferedImage.TYPE_INT_ARGB).outputFormat("png")
|
|
|
.toFile(outFilePath);
|
|
|
} else {
|
|
|
- Thumbnails.of(outFilePath).scale(1f).outputQuality(0.8).toFile(outFilePath);
|
|
|
+ Thumbnails.of(bufferedImage).scale(1f).outputQuality(0.8).toFile(outFilePath);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
File outFile = new File(outFilePath);
|
|
|
LogUtil.info(logger, "压缩后文件大小:{0}", outFile.length()/ 1024);
|
|
|
- QcloudFileUtils.putFile(outFile, thumbName, bucketName, mimeType);
|
|
|
+ if (outFile.length() < file.getSize()) {
|
|
|
+ QcloudFileUtils.putFile(outFile, thumbName, bucketName, mimeType);
|
|
|
+ } else {
|
|
|
+ // 如果大小没被压缩,则用原图作为缩略图
|
|
|
+ QcloudFileUtils.putStream(file.getInputStream(), thumbName, bucketName, mimeType );
|
|
|
+ }
|
|
|
if(outFile.exists()) {
|
|
|
LogUtil.info(log, "delete file..."+outFilePath);
|
|
|
outFile.delete();
|