Skip to content

Commit f869627

Browse files
committed
Fix fillcropspace param bug
1 parent 75def6b commit f869627

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/src/calculators/calculate_crop_fit_params.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:math';
2+
13
import 'package:custom_image_crop/src/models/params_model.dart';
24
import 'package:custom_image_crop/src/widgets/custom_image_crop_widget.dart';
35

@@ -25,11 +27,11 @@ CropFitParams calculateCropFitParams({
2527
if (screenWidth <= screenHeight * aspectRatio) {
2628
cropSizeWidth = screenWidth * cropPercentage;
2729
cropSizeHeight = cropSizeWidth / aspectRatio;
28-
defaultScale = cropSizeWidth / imageWidth;
30+
defaultScale = cropSizeWidth * max(imageWidth / imageHeight, 1.0) / imageWidth;
2931
} else {
3032
cropSizeHeight = screenHeight * cropPercentage;
3133
cropSizeWidth = cropSizeHeight * aspectRatio;
32-
defaultScale = cropSizeHeight / imageHeight;
34+
defaultScale = cropSizeHeight * max(imageHeight / imageWidth, 1.0) / imageHeight;
3335
}
3436
break;
3537

lib/src/calculators/calculate_on_crop_params.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@ OnCropParams caclulateOnCropParams({
2828

2929
switch (imageFit) {
3030
case CustomImageFit.fillCropSpace:
31+
double cropScale;
3132
if (screenWidth > screenHeight * aspectRatio) {
3233
uiSize = screenHeight;
3334
cropSizeMax = imageHeight.toDouble();
35+
cropScale = max(cropSizeMax / imageWidth, 1.0);
3436
} else {
3537
uiSize = screenWidth;
3638
cropSizeMax = imageWidth.toDouble();
39+
cropScale = max(cropSizeMax / imageHeight, 1.0);
3740
}
3841
translateScale = cropSizeMax / (uiSize * cropPercentage);
39-
scale = dataScale;
42+
scale = dataScale * cropScale;
4043
break;
4144

4245
case CustomImageFit.fitCropSpace:

0 commit comments

Comments
 (0)