mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-09-23 20:44:42 +08:00
弃用jimp
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
const Jimp = require("jimp");
|
||||
|
||||
const imageProcessor = async (imagePath) => {
|
||||
try {
|
||||
// 读取图片
|
||||
const image = await Jimp.read(imagePath);
|
||||
|
||||
// 获取原始尺寸
|
||||
const originalWidth = image.getWidth();
|
||||
const originalHeight = image.getHeight();
|
||||
const ratio = originalWidth / originalHeight;
|
||||
|
||||
// 设置目标尺寸
|
||||
let targetWidth = 1280;
|
||||
let targetHeight = 720;
|
||||
|
||||
if (ratio > 16 / 9) {
|
||||
targetHeight = Math.min(720, Math.round(targetWidth / ratio));
|
||||
} else {
|
||||
targetWidth = Math.min(1280, Math.round(targetHeight * ratio));
|
||||
}
|
||||
|
||||
// 调整大小并压缩
|
||||
await image
|
||||
.resize(targetWidth, targetHeight, Jimp.RESIZE_BICUBIC)
|
||||
.quality(80);
|
||||
|
||||
// 转换为 base64
|
||||
const base64 = await image.getBase64Async(Jimp.MIME_JPEG);
|
||||
|
||||
return base64;
|
||||
} catch (error) {
|
||||
console.error("处理图片失败:", error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = imageProcessor;
|
@@ -3,19 +3,17 @@ const path = require("path");
|
||||
const iconv = require("iconv-lite");
|
||||
const child_process = require("child_process");
|
||||
|
||||
const getBase64Ico = (filepath) => {
|
||||
let sourceImage,
|
||||
const resolveFileToBase64 = (filepath) => {
|
||||
let imageBase64,
|
||||
ext = path.extname(filepath).slice(1);
|
||||
if (["png", "jpg", "jpeg", "bmp", "ico", "gif", "svg"].includes(ext)) {
|
||||
if (ext == "svg") ext = "svg+xml";
|
||||
sourceImage =
|
||||
imageBase64 =
|
||||
`data:image/${ext};base64,` + fs.readFileSync(filepath, "base64");
|
||||
if (ext == "png") return sourceImage;
|
||||
} else {
|
||||
sourceImage = window.utools.getFileIcon(filepath);
|
||||
return sourceImage;
|
||||
imageBase64 = window.utools.getFileIcon(filepath);
|
||||
}
|
||||
return sourceImage;
|
||||
return imageBase64;
|
||||
};
|
||||
|
||||
const getFileInfo = (options) => {
|
||||
@@ -98,7 +96,7 @@ const convertFilePathToUtoolsPayload = (files) => {
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getBase64Ico,
|
||||
resolveFileToBase64,
|
||||
getFileInfo,
|
||||
getCurrentFolderPathFix,
|
||||
saveFile,
|
||||
|
Reference in New Issue
Block a user