srecord noeq PadImageToAspectRatio(BufferedImage img, Ratio ratio, Color color) > Meta { BufferedImage out; *(BufferedImage *img, double ratio, Color *color) { this.ratio = Ratio(ratio); } 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 > actualRatio) // target ratio is wider w2 = iround(h2*targetRatio); else h2 = iround(w2/targetRatio); if (scaffolding()) printVars(+w, +h, +w2, +h2, +actualRatio, +targetRatio, ratio := this.ratio); if (w == w2 && h == h2) ret img; out = isFullyTransparent(color) ? newTransparentImage(w2, h2) : newImage(w2, h2, color); drawImageOnImage(img, out, (w2-w)/2, (h2-h)/2); ret out; } }