static BufferedImage scaleBufferedImageToMaxWidthOrHeight(int max, BufferedImage img) { int w = img.getWidth(), h = img.getHeight(); if (w <= max && h <= max) ret img; double scale = max/(double) max(w, h); ret scaleImage(img, scale); } static BufferedImage scaleBufferedImageToMaxWidthOrHeight(BufferedImage img, int max) { ret scaleBufferedImageToMaxWidthOrHeight(max, img); }