Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static int[] scaleImageSize(int[] img_size, int square_size) { if (img_size[0] <= square_size && img_size[1] <= square_size) return img_size; double ratio = square_size / (double) Math.max(img_size[0], img_size[1]); return new int[] { (int) (img_size[0] * ratio), (int) (img_size[1] * ratio) }; } }