use smaller dimension
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon, 17 Nov 2014 23:18:41 +0100
changeset 19cda209705642
parent 18 a5a36526ff71
child 20 4e4ad30c17d4
use smaller dimension
java/copy-image-resizer/src/cz/frantovo/copyImageResizer/JavaSingleImageResizer.java
     1.1 --- a/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/JavaSingleImageResizer.java	Mon Nov 17 23:08:26 2014 +0100
     1.2 +++ b/java/copy-image-resizer/src/cz/frantovo/copyImageResizer/JavaSingleImageResizer.java	Mon Nov 17 23:18:41 2014 +0100
     1.3 @@ -55,13 +55,14 @@
     1.4  
     1.5  		int width;
     1.6  		int height;
     1.7 -		float aspectRatio = (float) original.getWidth() / (float) original.getHeight();
     1.8 +		float originalAspectRatio = (float) original.getWidth() / (float) original.getHeight();
     1.9 +		float requestedAspectRatio = (float) maxWidth / (float) maxHeight;
    1.10  
    1.11 -		if (aspectRatio > 1) {
    1.12 +		if (originalAspectRatio > requestedAspectRatio) {
    1.13  			width = maxWidth;
    1.14 -			height = Math.max(Math.round(maxWidth / aspectRatio), 1);
    1.15 +			height = Math.max(Math.round(maxWidth / originalAspectRatio), 1);
    1.16  		} else {
    1.17 -			width = Math.max(Math.round(maxHeight * aspectRatio), 1);
    1.18 +			width = Math.max(Math.round(maxHeight * originalAspectRatio), 1);
    1.19  			height = maxHeight;
    1.20  		}
    1.21