cropImage method

Future<CroppedFile?> cropImage({
  1. required String sourcePath,
  2. int? maxWidth,
  3. int? maxHeight,
  4. CropAspectRatio? aspectRatio,
  5. ImageCompressFormat compressFormat = ImageCompressFormat.jpg,
  6. int compressQuality = 90,
  7. List<PlatformUiSettings>? uiSettings,
})

Launch cropper UI for an image.

parameters:

  • sourcePath: the absolute path of an image file.

  • maxWidth: maximum cropped image width.

  • maxHeight: maximum cropped image height.

  • aspectRatio: controls the aspect ratio of crop bounds. If this values is set, the cropper is locked and user can't change the aspect ratio of crop bounds.

  • compressFormat: the format of result image, png or jpg (default is ImageCompressFormat.jpg)

  • compressQuality: the value 0 - 100 to control the quality of image compression

  • uiSettings: controls UI customization on specific platform (android, ios, web,...)

See:

return:

A result file of the cropped image.

Note:

  • The result file is saved in NSTemporaryDirectory on iOS and application Cache directory on Android, so it can be lost later, you are responsible for storing it somewhere permanent (if needed).

  • The implementation on Web is much different compared to the implementation on mobile app. It causes some configuration fields not working (maxWidth, maxHeight, aspectRatio, aspectRatioPresets) and WebUiSettings is required for Web.

Implementation

Future<CroppedFile?> cropImage({
  required String sourcePath,
  int? maxWidth,
  int? maxHeight,
  CropAspectRatio? aspectRatio,
  ImageCompressFormat compressFormat = ImageCompressFormat.jpg,
  int compressQuality = 90,
  List<PlatformUiSettings>? uiSettings,
}) {
  return platform.cropImage(
    sourcePath: sourcePath,
    maxWidth: maxWidth,
    maxHeight: maxHeight,
    aspectRatio: aspectRatio,
    compressFormat: compressFormat,
    compressQuality: compressQuality,
    uiSettings: uiSettings,
  );
}