modelImageSize function
Target pixel size when the longest side is capped at maxSize (0 = no cap); never upscales.
Implementation
({int width, int height}) modelImageSize(int width, int height, int maxSize) {
final longest = width > height ? width : height;
if (maxSize <= 0 || longest <= maxSize) return (width: width, height: height);
final scale = maxSize / longest;
return (width: (width * scale).round(), height: (height * scale).round());
}