1
0
Fork 0
blabber-comic/helpers/files.js
2017-01-21 17:46:20 -06:00

26 lines
529 B
JavaScript

const fs = require('fs');
const Canvas = require('canvas');
function isImage(fileString) {
let ext = fileString.slice(fileString.indexOf('.'));
return ['.png', '.jpg'].indexOf(ext) > -1;
}
function readImageFromPath(path) {
return new Promise(resolve => {
fs.readFile(path, (err, loadedImage) => {
if (err) throw err;
let img = new Canvas.Image;
img.src = loadedImage;
resolve(img);
});
}).catch(error => {
throw error;
});
}
module.exports = {
isImage,
readImageFromPath
};