代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。