*/
@Nullable
public static Image createJpegThumbnail(@Nullable final byte[] imageBytes, final int lengthOfLongestSideInPixels) throws IOException {
if (imageBytes != null && imageBytes.length > 0 && lengthOfLongestSideInPixels > 0) {
ImageOrientation orientation = ImageOrientation.getOrientation(new ByteArrayInputStream(imageBytes));
if (orientation == null) {
orientation = ImageOrientation.ORIENTATION_1;
}
try {
BufferedImage image = convertToBufferedImage(imageBytes);
if (image != null) {
// drop the alpha channel, if one exists
if (image.getColorModel().hasAlpha()) {
image = dropAlphaChannel(image);
}
return JpegImage.create(orientation.transform(Scalr.resize(image, Scalr.Method.AUTOMATIC, Scalr.Mode.AUTOMATIC, lengthOfLongestSideInPixels)));
}
}
catch (Exception e) {
final String message = "Exception while trying to create a thumbnail";
LOG.error(message, e);