添加图片预览api
This commit is contained in:
31
bin/util/vips.dart
Normal file
31
bin/util/vips.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
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!");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user