3 Star 43 Fork 14

JYeontu/nodeScriptingTool

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
util.js 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
JYeontu 提交于 2022-07-30 11:28 +08:00 . 图片拼接工具优化
const sharp = require("sharp");
getFileSuffix = (fileName, splitChar) => {
// 取字符最后一次出现的位置(根据需要选择)
const first = fileName.lastIndexOf(splitChar);
const namelength = fileName.length; //取到文件名长度
return fileName.substring(first + 1, namelength); //截取获得后缀名
}
getFilePath = (fileName, splitChar) => {
// 取字符最后一次出现的位置(根据需要选择)
const first = fileName.lastIndexOf(splitChar);
const namelength = fileName.length;
return fileName.substring(0, first);
}
getMetadata = async(path) => {
return await sharp(path).metadata();
}
resizeImage = async(params) => {
const {path,height,width} = params;
const targetPath = getFilePath(path,'.') + '-tmp.' + getFileSuffix(path,'.');
try {
await sharp(path)
.resize({
width: width,
height: height
})
.toFile(targetPath);
return targetPath;
} catch (error) {
console.log(error);
}
}
module.exports = {
getFileSuffix,
getMetadata,
resizeImage
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/zheng_yongtao/node-scripting-tool.git
git@gitee.com:zheng_yongtao/node-scripting-tool.git
zheng_yongtao
node-scripting-tool
nodeScriptingTool
master

搜索帮助