32 lines
661 B
Dart
32 lines
661 B
Dart
import 'dart:io';
|
|
|
|
import 'package:path/path.dart';
|
|
|
|
class Vips {
|
|
String? vipsExecuteFile;
|
|
|
|
Vips({this.vipsExecuteFile});
|
|
|
|
Future<File> generatePreview(String imgPath) async {
|
|
final imgOut =
|
|
"cache/preview/" + basename(imgPath).hashCode.toString() + ".webp";
|
|
final outFile = File(imgOut);
|
|
if (outFile.existsSync()) {
|
|
return outFile;
|
|
}
|
|
final result = await Process.run("vips", [
|
|
"webpsave",
|
|
imgPath,
|
|
imgOut,
|
|
"--Q",
|
|
"80",
|
|
"--smart-subsample",
|
|
"--strip",
|
|
]);
|
|
if (result.exitCode == 0) {
|
|
return outFile;
|
|
}
|
|
throw Exception("vips image transcode failed!");
|
|
}
|
|
}
|