添加图片预览api

This commit is contained in:
2026-03-13 22:07:33 +08:00
parent 8612b2dbde
commit 4be862d66b
16 changed files with 218 additions and 17 deletions

31
bin/util/vips.dart Normal file
View 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!");
}
}