Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: No image displayed when ImageResizeService throw an error - EXO-74337 #651

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,19 @@ public byte[] scaleImage(byte[] image, int width, int height, boolean fitExact,
}
bufferedImage = Scalr.resize(bufferedImage, resizeMethod, fitMode, width, height, Scalr.OP_ANTIALIAS);
}


byte[] response = toByteArray(bufferedImage, imageReader);

if (!fitExact && response.length > image.length) {
// if the original image is smaller in weight from the resized image, we
// must keep the original image
try {
byte[] response = toByteArray(bufferedImage, imageReader);

if (!fitExact && response.length > image.length) {
// if the original image is smaller in weight from the resized image, we
// must keep the original image
return image;
} else {
return response;
}
} catch (IOException e) {
LOG.error("Unable to read image to resize, return original size",e);
return image;
} else {
return response;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,21 @@ public void testShouldFitHeight() {
fail();
}
}

@Test
public void testResizeJpegWithNotSupportedMetadata() throws Exception {

File
fileImage =
new File(getClass().getClassLoader().getResource("images/illustration_with_non_supported_metadata.jpeg").getFile());
byte[] testFileImage = Files.readAllBytes(fileImage.toPath());
try {
byte[] resizedImage = imageResizeService.scaleImage(testFileImage, 250, 150, false, true);
assertEquals(resizedImage.length, testFileImage.length);
} catch (Exception e) {
fail("ScaleImage throws an error, and we do not catch it");
}

}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading