Fixed auto-resizing images

This commit is contained in:
nathan 2017-09-17 17:41:37 +02:00
parent 9d92c9749d
commit 104717c016

View File

@ -220,11 +220,22 @@ class ImageResizeUtil {
// if it's already there, we have to delete it
newFile.delete();
// resize the image, keep aspect ratio
Image image = ImageUtil.getImageImmediate(ImageIO.read(inputStream));
// the smaller dimension have padding, so the larger dimension is the size of this image.
BufferedImage bufferedImage = ImageUtil.getSquareBufferedImage(image);
BufferedImage bufferedImage = ImageUtil.getBufferedImage(image);
// resize the image, keep aspect ratio
int width = bufferedImage.getWidth();
int height = bufferedImage.getHeight();
if (width > height) {
bufferedImage = ImageUtil.resizeImage(bufferedImage, size, -1);
}
else {
bufferedImage = ImageUtil.resizeImage(bufferedImage, -1, size);
}
// make the image "square" so there is padding on the sides that are smaller
bufferedImage = ImageUtil.getSquareBufferedImage(bufferedImage);
// now write out the new one
ImageIO.write(bufferedImage, "png", newFile); // made up extension