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,
|
||||
|
1661
plugin/package-lock.json
generated
1661
plugin/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,6 @@
|
||||
"axios": "^1.7.9",
|
||||
"crypto-js": "^4.2.0",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"jimp": "^0.22.12",
|
||||
"lodash": "^4.17.21",
|
||||
"node-forge": "^1.3.1",
|
||||
"ses": "^1.10.0",
|
||||
|
@@ -21,7 +21,7 @@ const getCommandToLaunchTerminal = require("./lib/getCommandToLaunchTerminal");
|
||||
const shortCodes = require("./lib/shortCodes");
|
||||
const { pluginInfo, getUtoolsPlugins } = require("./lib/getUtoolsPlugins");
|
||||
const {
|
||||
getBase64Ico,
|
||||
resolveFileToBase64,
|
||||
getFileInfo,
|
||||
getCurrentFolderPathFix,
|
||||
saveFile,
|
||||
@@ -30,7 +30,7 @@ const {
|
||||
} = require("./lib/utils");
|
||||
window.pluginInfo = pluginInfo;
|
||||
window.getUtoolsPlugins = getUtoolsPlugins;
|
||||
window.getBase64Ico = getBase64Ico;
|
||||
window.resolveFileToBase64 = resolveFileToBase64;
|
||||
window.getFileInfo = getFileInfo;
|
||||
window.getCurrentFolderPathFix = getCurrentFolderPathFix;
|
||||
window.saveFile = saveFile;
|
||||
@@ -41,7 +41,6 @@ window.getuToolsLite = require("./lib/utoolsLite");
|
||||
window.quickcommand = require("./lib/quickcommand");
|
||||
window.quickcomposer = require("./lib/quickcomposer");
|
||||
window.getQuickcommandTempFile = require("./lib/getQuickcommandTempFile");
|
||||
window.imageProcessor = require("./lib/imageprocessor");
|
||||
window.showUb = require("./lib/showDocs");
|
||||
|
||||
window.getSharedQcById = async (id) => {
|
||||
@@ -98,7 +97,6 @@ window.removeHtmlTags = (value) => {
|
||||
return quickcommand.htmlParse(value).querySelector("body").innerText;
|
||||
};
|
||||
|
||||
|
||||
window.hexEncode = (text) => Buffer.from(text, "utf8").toString("hex");
|
||||
window.hexDecode = (text) => Buffer.from(text, "hex").toString("utf8");
|
||||
window.base64Decode = (text) => Buffer.from(text, "base64").toString("utf8");
|
||||
|
Reference in New Issue
Block a user