Skip to content
Snippets Groups Projects
Verified Commit fa8bae3e authored by Isabella Skořepová's avatar Isabella Skořepová
Browse files

Fix race condition in imageResizer

parent 5e1dd667
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,8 @@ catch(e) {
console.log('You can try to run npm install.');
console.log('If it does not help try to make npm install lwip work.');
}
var mkdirp = require('mkdirp');
var path = require('path');
module.exports = function(file, targetDir, width, height) {
if(lwip && (width || height)) {
......@@ -23,11 +25,13 @@ module.exports = function(file, targetDir, width, height) {
targetFile = path.resolve(targetDir,targetFile);
lwip.open(file, function(err, image) {
function doResize() {
image.batch()
.resize(width, height)
.writeFile(targetFile, function(err) {
if(err) console.log(err);
});
mkdirp(path.dirname(targetFile), function() {
image.batch()
.resize(width, height)
.writeFile(targetFile, function(err) {
if(err) console.log(err);
});
}
}
if(err) return console.log(err);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment