limitSize static method

RgbaImage limitSize(
  1. RgbaImage src,
  2. int maxDim
)

Resize so the long side is at most maxDim (no-op when small enough).

Implementation

static RgbaImage limitSize(RgbaImage src, int maxDim) {
  final long = src.width > src.height ? src.width : src.height;
  if (long <= maxDim) return src;
  final scale = maxDim / long;
  final dw = (src.width * scale).round().clamp(1, maxDim);
  final dh = (src.height * scale).round().clamp(1, maxDim);
  return resize(src, dw, dh);
}