compress static method

Future<File?> compress({
  1. required File image,
  2. CompressParams compressParams = defaultCompress,
})

Implementation

static Future<File?> compress({
  required File image,
  CompressParams compressParams = defaultCompress,
}) async {
  var dir = await getTemporaryDirectory();
  var targetPath = '${dir.path}/compressed_${DateTime.now().millisecondsSinceEpoch}.jpg';

  var compressedFile = await FlutterImageCompress.compressAndGetFile(
    image.absolute.path,
    targetPath,
    quality: compressParams.quality,
    minHeight: compressParams.targetHeight,
    minWidth: compressParams.targetWidth,
  );

  if (compressedFile == null) {
    debugPrint('Compression failed');
    return null;
  }

  return File(compressedFile.path);
}