Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Flesh out the package.json a little * Split out CLI from main code
- Loading branch information
1 parent
627dac4
commit 6ca55e1
Showing
6 changed files
with
170 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
require('../lib/cli').run(__filename); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const fs = require("fs"); | ||
const minimist = require("minimist"); | ||
const PartyPartyParty = require("../index"); | ||
|
||
function run(launchFilePath) { | ||
// Process the arguments we're launched with and get rid of anything we won't be using. | ||
args = minimist(process.argv, { | ||
default: { | ||
"radius": 10, // 0 = regular stationary party | ||
}, | ||
unknown: arg => { | ||
// Filter out node and our index.js. | ||
// This ensures that the args._ array will just be the files we process | ||
if (arg === process.execPath) return false; | ||
if (arg === (launchFilePath || __filename)) return false; | ||
return true; | ||
} | ||
}); | ||
|
||
//TODO(somewhatabstract): Consider adding some scaling or a --fitslack option? | ||
//TODO(somewhatabstract): Add ability to specify lots of different files at once. | ||
//TODO(somewhatabstract): Add error checks and useful help text. | ||
if (args._.length !== 2) { | ||
console.log("Usage: " + (launchFilePath || __filename) + " input.png output.gif"); | ||
process.exit(-1); | ||
} | ||
|
||
const inputFilename = args._[0]; | ||
const outputFilename = args._[1]; | ||
|
||
const outputFileStream = fs.createWriteStream(outputFilename); | ||
PartyPartyParty(inputFilename, outputFileStream, parseInt(args.radius)); | ||
} | ||
|
||
module.exports = { | ||
run | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
function toGreyscale(pixels) { | ||
const greyscale = []; | ||
|
||
for (var i = 0; i < pixels.data.length / 4; i += 1) { | ||
const idx = i * 4; | ||
if (pixels.data[idx + 3] < 64) { | ||
greyscale.push(-1); | ||
} else { | ||
const avg = | ||
(pixels.data[idx] + | ||
pixels.data[idx + 1] + | ||
pixels.data[idx + 2]) / | ||
3; | ||
greyscale.push(avg); | ||
} | ||
} | ||
return greyscale; | ||
} | ||
|
||
module.exports = toGreyscale; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters