Skip to content

Commit

Permalink
#527 resize only if bigger than 500px
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Oct 31, 2018
1 parent ccb4299 commit 4711a8b
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,21 @@ public ResponseEntity<String> uploadFile(@RequestParam(required = false, value =
try {

if (resizeImage) {
UploadBase64FileModification resized = new UploadBase64FileModification();

BufferedImage image = ImageIO.read(new ByteArrayInputStream(upload.getFile()));
BufferedImage thumbImg = Scalr.resize(image, Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, 500, 500, Scalr.OP_ANTIALIAS);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(thumbImg, "png", baos);
//resize only if the image is bigger than 500px on one of the side
if(image.getWidth() > 500 || image.getHeight() > 500) {
UploadBase64FileModification resized = new UploadBase64FileModification();
BufferedImage thumbImg = Scalr.resize(image, Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, 500, 500, Scalr.OP_ANTIALIAS);
ByteArrayOutputStream baos = new ByteArrayOutputStream();

ImageIO.write(thumbImg, "png", baos);

resized.setFile(baos.toByteArray());
resized.setAttributes(upload.getAttributes());
resized.setName(upload.getName());
resized.setType("image/png");
upload = resized;
resized.setFile(baos.toByteArray());
resized.setAttributes(upload.getAttributes());
resized.setName(upload.getName());
resized.setType("image/png");
upload = resized;
}
}

return ResponseEntity.ok(fileUploadManager.insertFile(upload));
Expand Down

0 comments on commit 4711a8b

Please sign in to comment.