compressImage method

Future<File?> compressImage(
  1. File file, {
  2. int? quality = 50,
  3. int? rotate = 0,
})

This function is used to get compress image

Implementation

Future<File?> compressImage(File file,
    {int? quality = 50, int? rotate = 0}) async {
  String? str = FileSupport().getFileExtension(file);

  ("The file extension of image" + str!).printinfo;
  if (FileSupport().getFileType(file).toLowerCase() != "image") {
    "Only Images are used for compression".printinfo;
    return null;
  }

  var result = await FlutterImageCompress.compressWithFile(
    file.absolute.path,
    quality: quality!,
    rotate: rotate!,
  );
  print("Compress data is${file.lengthSync()}");
  print("Compress data is${result!.length}");

  File? compressimage = await FileSupport()
      .writeUint8ListtoTemporaryDirectory(
          data: result, extension: FileSupport().getFileExtension(file));

  return compressimage;
}