Skip to content

Commit

Permalink
fix: 检查webp是否锤子
Browse files Browse the repository at this point in the history
  • Loading branch information
litten committed Oct 7, 2017
1 parent 7bbe339 commit 0d448b1
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function handleFile(path, floor) {
var md5Name = crypto.createHash('md5').update(nodePath.join(path)).digest('hex')
var imgPath = './tmp/' + md5Name + '.jpg';
var imgLargePath = './tmp_large/' + md5Name + '.jpg';
var imgwebPPath = './tmp_webp/' + md5Name + '.webp';
fs.exists(imgPath, function(exists) {
if (!exists) {
images(path)
Expand All @@ -66,13 +67,17 @@ function handleFile(path, floor) {
});

// 文件名空格处理
var webpLine = path.replace(/\s/g, '%20') + ' -q 80 -o ./tmp_webp/' + md5Name + '.webp';
var webpLineSplit = webpLine.split(/\s+/);
var webpLineArr = [];
for (var i = 0, len = webpLineSplit.length; i < len; i++) {
webpLineArr.push(webpLineSplit[i].replace(/%20/g, ' '));
}
spawn(webpBinPath, webpLineArr);
fs.exists(imgwebPPath, function (exists) {
if (!exists) {
var webpLine = path.replace(/\s/g, '%20') + ' -q 80 -o ./tmp_webp/' + md5Name + '.webp';
var webpLineSplit = webpLine.split(/\s+/);
var webpLineArr = [];
for (var i = 0, len = webpLineSplit.length; i < len; i++) {
webpLineArr.push(webpLineSplit[i].replace(/%20/g, ' '));
}
spawn(webpBinPath, webpLineArr);
}
});
}
}
})
Expand Down

0 comments on commit 0d448b1

Please sign in to comment.