Skip to content
This repository has been archived by the owner on Apr 19, 2020. It is now read-only.

Handle directory as input #3

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

thinker3197
Copy link

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.

@coveralls
Copy link

coveralls commented Mar 27, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 1b452c8 on thinker3197:master into e2ded4f on thiamsantos:master.

@@ -0,0 +1,3 @@
{
Copy link
Owner

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 => {
Copy link
Owner

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.

Copy link
Owner

@thiamsantos thiamsantos Mar 30, 2017

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.

@thiamsantos
Copy link
Owner

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')
Copy link
Owner

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) {
Copy link
Owner

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))
Copy link
Owner

@thiamsantos thiamsantos Mar 31, 2017

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 @@
{
Copy link
Owner

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants