# HG changeset patch # User František Kučera # Date 1416262721 -3600 # Node ID cda20970564291cbf9632ccc7a7b5d94542a7786 # Parent a5a36526ff7106d022ab97b7afc42cd17d4fe301 use smaller dimension diff -r a5a36526ff71 -r cda209705642 java/copy-image-resizer/src/cz/frantovo/copyImageResizer/JavaSingleImageResizer.java --- a/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/JavaSingleImageResizer.java Mon Nov 17 23:08:26 2014 +0100 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/JavaSingleImageResizer.java Mon Nov 17 23:18:41 2014 +0100 @@ -55,13 +55,14 @@ int width; int height; - float aspectRatio = (float) original.getWidth() / (float) original.getHeight(); + float originalAspectRatio = (float) original.getWidth() / (float) original.getHeight(); + float requestedAspectRatio = (float) maxWidth / (float) maxHeight; - if (aspectRatio > 1) { + if (originalAspectRatio > requestedAspectRatio) { width = maxWidth; - height = Math.max(Math.round(maxWidth / aspectRatio), 1); + height = Math.max(Math.round(maxWidth / originalAspectRatio), 1); } else { - width = Math.max(Math.round(maxHeight * aspectRatio), 1); + width = Math.max(Math.round(maxHeight * originalAspectRatio), 1); height = maxHeight; }