-
Notifications
You must be signed in to change notification settings - Fork 2
Handle directory as input #3
base: master
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,3 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add these file from vscode to gitignore, and remove them.
Just add .vscode/*
to the end of the gitignore file.
bin/lowly.js
Outdated
@@ -44,4 +48,46 @@ input.forEach(file => { | |||
}).catch(err => { | |||
console.error(err) | |||
}) | |||
} | |||
|
|||
input.forEach(ip => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove all this fancy check to see if the files are directories, and just check if the string receveid by the forEach
is an supported image? The module resize-img supports bmp
, jpg
and png
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use the module file-extension.
Looks good to me @thinker3197 ! I'll just test locally and give you a return as soon as possible. |
@@ -5,8 +5,12 @@ const path = require('path') | |||
const filesize = require('filesize') | |||
const meow = require('meow') | |||
const pify = require('pify') | |||
const mmm = require('mmmagic') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could change the library, because mmmagic
rely on node-gyp for compile the native addons used. That can be a problem when you are running windows beacause you must have installed properly both the node-gyp
and the windows-build-tools for node. So, I think that mmmagic
adds unnecessary complexity.
An library that does almost the same thing is file-type but doesn't rely on native addons.
const checkType = (buff, file) => { | ||
return new Promise((resolve, reject) => { | ||
magic.detect(buff, (err, res) => { | ||
if (res.indexOf('image') >= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is only verified if the file is an image. But, not all image formats that are support, only bmp
, jpg
and png
. So you should verify these formats.
input.forEach(file => { | ||
readFile(path.resolve(file)) | ||
.then(buff => checkType(buff, file)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to verify the files before read them? I'm not sure but this can reduce the processing cost.
@@ -0,0 +1,3 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not forget to delete this file from the repo.
Most projects would likely have a image/asset folder where images will be saved. Lowly should handle cases for having directory inputs.
Lowly cli will parse all images in the given input directory and create lower resolution images for the same in the same directory.