toWebp static method

Future<File?> toWebp(
  1. File input,
  2. String outputPath, {
  3. int quality = 80,
})

Converts an image to WebP format.

Implementation

static Future<File?> toWebp(
  File input,
  String outputPath, {
  int quality = 80,
}) async {
  if (_cwebpPath == null) return null;

  try {
    final result = await Process.run(
      _cwebpPath!,
      ['-q', quality.toString(), input.path, '-o', outputPath],
    );

    if (result.exitCode == 0 && await File(outputPath).exists()) {
      return File(outputPath);
    }
  } catch (_) {}
  return null;
}