Configure compression with minWidth and minHeight
mainUse minWidth and minHeight to bound the output size while preserving the source aspect ratio.
Important Behavior:
- The plugin calculates a scale based on these bounds. It will scale the image down to fit within these dimensions, but it will never upscale an image. If the source is already smaller than the provided bounds, the scale is clamped to 1.
- Despite the names, these act like maximum bounds for the output dimensions.
// Illustrative Dart port of the native logic.
import 'dart:math' as math;
void main() {
final scale = calcScale(
srcWidth: 4000,
srcHeight: 2000,
minWidth: 1920,
minHeight: 1080,
);
print('scale = $scale'); // 1.8518518518518519
print('target = ${4000 / scale} × ${2000 / scale}'); // 2160.0 × 1080.0
}
double calcScale({
required double srcWidth,
required double srcHeight,
required double minWidth,
required double minHeight,
}) {
final scaleW = srcWidth / minWidth;
final scaleH = srcHeight / minHeight;
return math.max(1.0, math.min(scaleW, scaleH));
}