How to add custom crop ratio into image_cropper library - Flutter
Asked Answered
T

2

2

I know Image_cropper support predefined crop ratio like

 aspectRatioPresets: [
        CropAspectRatioPreset.square,
        CropAspectRatioPreset.ratio3x2,
        CropAspectRatioPreset.original,
        CropAspectRatioPreset.ratio4x3,
        CropAspectRatioPreset.ratio16x9
      ],

But I need to add a custom ratio say 9x16 or 7x5. What is the best solution for it?

https://pub.dev/packages/image_cropper

Threesquare answered 3/3, 2021 at 9:22 Comment(0)
E
4

I have not be able to find a way to provide a list of "unique" aspect ratios using only one cropImage call, however you can provide a single aspect ratio in X, Y form.

you could have a UI button labeled "crop 9x16" and another button labeled "crop 7x5" with the following method inside the button's on_pressed function.

ImageCropper.cropImage(
  sourcePath: path, // your image file path
  aspectRatio: CropAspectRatio(ratioX: 9, ratioY: 16)) //your desired aspect ratio
Etiquette answered 26/9, 2021 at 2:52 Comment(0)
C
0

You can use crop_image flutter package which is available in pub.dev for your specific image cropping functionalities.

Check the process which is useful for you from the package-documentation.

Continuum answered 22/6 at 13:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.