Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit f554de9570a7bcf78e40ff641e2c876023d74d87 @remixz remixz committed Nov 13, 2012
Showing with 124 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +1 −0 README.md
  3. +10 −0 bin/index.js
  4. +12 −0 lib/example.js
  5. +68 −0 lib/wizardry.js
  6. +25 −0 package.json
  7. +6 −0 tasks/sepia.json
2 .gitignore
@@ -0,0 +1,2 @@
+/node_modules
+.DS_Store
1 README.md
@@ -0,0 +1 @@
+Todo.
@thisandagain
thisandagain added a note Nov 14, 2012

Along the same lines as encouraging you to write tests first and then the implementation, I highly encourage you to rough-in your readme first before anything else. This makes you think about the end user, the use cases and how your module will fit into the larger ecosystem first before starting to write your implementation. Think of it as your wireframe before you start to design! :smile:

@remixz
remixz added a note Nov 14, 2012

Yeah, I'll be doing that after school. Thanks for all the feedback! :smile:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
10 bin/index.js
@@ -0,0 +1,10 @@
+#!/usr/bin/env node
+var argv = require('optimist').demand(['i', 't']).argv,
+ wizardry = require('./../lib/wizardry');
+
+var callback = function(err) {
+ if (err) { console.dir(err); };
+}
+
+wizardry([__dirname + '/' + argv.i], require('./' + argv.t), callback);
+
12 lib/example.js
@@ -0,0 +1,12 @@
+var wizardry = require('./lib/wizardry');
+var task = require('./tasks/rotate');
+
+var callback = function(status) {
+ if (status === false) {
+ return false;
+ } else {
+ return true;
+ }
+}
+
+wizardry.process('aHHVC.png', task, callback());
68 lib/wizardry.js
@@ -0,0 +1,68 @@
+/**
+ * wizardry - A task-based library for graphicsmagick.
+ *
+ * Copyright (c) 2012 DIY Co
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
+ * file except in compliance with the License. You may obtain a copy of the License at:
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
+ * ANY KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ *
+ * @package wizardry
+ * @author Zachary Bruggeman <zbruggeman@me.com>
+ */
+
+var fs = require('fs'),
+ _ = require('lodash'),
+ async = require('async'),
+ spawn = require('child_process').spawn;
+
+var env = Object.create(null);
+_.defaults(env, {
+ cpu: require('os').cpus().length
+});
+
+/**
+ * Export
+ *
+ * @param {Array} Array of image paths
+ * @param {Object} Processing task to run
+ * @param {Function} Callback to be ran after finished processing
+ *
+ * @return {Error}
+ */
+
+module.exports = function (images, task, callback) {
+
+ var args = [];
+
+ // Task manager
+ args.push('mogrify');
+ if (task.outputDirectory) {
+ args.push('-output-directory ' + task.outputDirectory)
+ }
+
+ _.each(task.commands, function(arguments, com) {
+ args.push('-' + com);
+ args.push(arguments);
+ });
+
+ var queue = async.queue(function (filename, callback) {
+ var args_processed = args.slice(0);
+ args_processed.push(filename);
+ console.dir(args_processed);
+ var process = spawn('gm', args_processed);
+ process.on('exit', function(code) {callback();});
@thisandagain
thisandagain added a note Nov 14, 2012

You are going to want to make sure you catch the process exit signal, otherwise your error handling is moot:

process.on('exit', function (code) {
    if (code !== 0) return callback('Process ended with signal ' + code);
    callback();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }, env.cpu);
+
+ queue.push(images);
+
+ queue.drain = function(error) {
@thisandagain
thisandagain added a note Nov 14, 2012

This could be simplified to:

queue.drain = callback;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if (error) callback(error);
+ else callback();
+ }
+};
25 package.json
@@ -0,0 +1,25 @@
+{
+ "author": "Zachary Bruggeman <zbruggeman@me.com>",
+ "name": "wizardry",
+ "description": "A task based library for graphics-magick",
+ "version": "0.0.1",
+ "homepage": "https://github.com/remixz/wizardry",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/remixz/wizardry.git"
+ },
+ "bin": {
+ "wizardry": "./bin/index.js"
+ }
+ "main": "./lib/wizardry.js",
+ "dependencies": {
+ "lodash": "~0.8.1",
+ "async": "~0.1.22",
+ "optimist": "~0.3.5"
+ },
+ "devDependencies": {},
+ "optionalDependencies": {},
+ "engines": {
+ "node": ">=0.8"
+ }
+}
6 tasks/sepia.json
@@ -0,0 +1,6 @@
+{
+ "commands": {
+ "modulate": "115, 0, 100",
+ "colorize": "7, 21, 50"
+ }
+}

0 comments on commit f554de9

Please sign in to comment.
Something went wrong with that request. Please try again.