This PR modifies both the fit and resize functions to handle dimensions more consistently, with fit using a new calculation method and resize simplifying to always use the exact requested dimensions. This behavior regressed with the changes #178 , which this PR restores.
Changes:
Introduced calculateExpectedSize helper function used by the fit function.
Updated fit function to use this new helper function.
Simplified resize function to always use exact output dimensions.
Added min helper function for dimension comparisons.
Behavior Examples:
Fit function (new logic):
a. Both dimensions smaller than source:
Original: 800x600, Requested: 400x300
Result: 400x300 (scales down, maintaining aspect ratio, may crop)
b. Square fit larger than original:
Original: 800x600, Requested: 1000x1000
Result: 600x600 (fits within original dimensions)
c. Both dimensions larger than original:
Original: 800x600, Requested: 1000x800
Result: 800x600 (maintains original size)
d. Mixed scaling:
Original: 800x600, Requested: 1000x400
Result: 1000x400 (allows partial upscaling, maintains aspect ratio, may crop)
Resize function (updated behavior):
For all cases: Always resizes to exact requested dimensions
Example: Original: 800x600, Requested: 1000x750
Result: 1000x750 (resizes to exact dimensions, may change aspect ratio)
The new fit logic ensures that:
Downscaling maintains aspect ratio but may crop to fit exact dimensions.
Upscaling is prevented when both dimensions would increase.
Partial upscaling (one dimension only) is allowed, maintaining aspect ratio and potentially cropping.
Square fits larger than the original use the smaller original dimension.
The updated resize function now always resizes to the exact requested dimensions, potentially changing the aspect ratio.
These changes provide more predictable and consistent behavior for both functions, with fit focusing on maintaining aspect ratio (with potential cropping) and resize always producing the exact requested dimensions.
This PR modifies both the
fit
andresize
functions to handle dimensions more consistently, withfit
using a new calculation method andresize
simplifying to always use the exact requested dimensions. This behavior regressed with the changes #178 , which this PR restores.Changes:
calculateExpectedSize
helper function used by thefit
function.fit
function to use this new helper function.resize
function to always use exact output dimensions.min
helper function for dimension comparisons.Behavior Examples:
Fit function (new logic):
a. Both dimensions smaller than source: Original: 800x600, Requested: 400x300 Result: 400x300 (scales down, maintaining aspect ratio, may crop)
b. Square fit larger than original: Original: 800x600, Requested: 1000x1000 Result: 600x600 (fits within original dimensions)
c. Both dimensions larger than original: Original: 800x600, Requested: 1000x800 Result: 800x600 (maintains original size)
d. Mixed scaling: Original: 800x600, Requested: 1000x400 Result: 1000x400 (allows partial upscaling, maintains aspect ratio, may crop)
Resize function (updated behavior): For all cases: Always resizes to exact requested dimensions Example: Original: 800x600, Requested: 1000x750 Result: 1000x750 (resizes to exact dimensions, may change aspect ratio)
The new fit logic ensures that:
The updated resize function now always resizes to the exact requested dimensions, potentially changing the aspect ratio.
These changes provide more predictable and consistent behavior for both functions, with
fit
focusing on maintaining aspect ratio (with potential cropping) andresize
always producing the exact requested dimensions.