srecord noeq PadImageToAspectRatio(BufferedImage img, Ratio ratio, Color color) { BufferedImage out; BufferedImage get() { int w = img.getWidth(), h = img.getHeight(); double actualRatio = doubleRatio(w, h); double targetRatio = this.ratio!; int w2 = w, h2 = h; if (targetRatio > 1) // target ratio is wider w2 = iround(h2*targetRatio); else h2 = iround(h2/targetRatio); out = newImage(w2, h2, color); drawImageOnImage(img, out, (w2-w)/2, (h2-h)/2); ret out; } }