code: public static int[] shrinkImage(BufferedImage srcImg, String dest, int width, int height) throws IOException {
  		int w = srcImg.getWidth(null);
  		int h = srcImg.getHeight(null);
  
  		if (w <= width && h <= height) {
  			width = w;
  			height = h;
  		} else {
  			double r1 = (double) width / (double) w;
  			double r2 = (double) height / (double) h;
  
  			if (r1 > r2) {
  				width = (int) (w * r2);
  				height = (int) (h * r2);
  			} else {
  				width = (int) (w * r1);
  				height = (int) (h * r1);
  			}
  
  			if (width <= 0)
  				width = 1;
  			if (height <= 0)
  				height = 1;
  		}
  
  		int size = resizeImage(srcImg, dest, width, height);
  		return new int[] { width, height, size };
  	}
docs: 将源图片按比例缩放为指定的尺寸大小
  
  @param srcImg
  @param dest
  @param width
  @param height
  @throws IOException