Permalink
Browse files

Got rid of long gone sys module dependency as well as adding test mat…

…ter and did some long overdue clean up
  • Loading branch information...
1 parent 04bc6c9 commit 34c8debd2c7eea835c9d570d399cdfce0cc9c7c7 @rsms committed Sep 22, 2012
Showing with 72 additions and 79 deletions.
  1. +2 −0 .gitignore
  2. +3 −1 README.md
  3. +9 −14 package.json
  4. BIN sample-images/blue-bottle-coffee.jpg
  5. +31 −38 test-crop.js
  6. +27 −26 test.js
View
@@ -0,0 +1,2 @@
+**.DS_Store
+*.jpg
View
@@ -6,6 +6,8 @@ You can install this module using [npm](http://github.com/isaacs/npm):
npm install imagemagick
+Requires imagemagick CLI tools to be installed. There are numerous ways to install them. For instance, if you're on OS X you can use [Homebrew](http://mxcl.github.com/homebrew/): `brew install imagemagick`.
+
## Example
var im = require('imagemagick');
@@ -139,7 +141,7 @@ Example:
## License (MIT)
-Copyright (c) 2010-2011 Rasmus Andersson <http://hunch.se/>
+Copyright (c) 2010-2012 Rasmus Andersson <http://hunch.se/>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
View
@@ -1,15 +1,10 @@
-{
- "name": "imagemagick",
- "description": "A wrapper around the imagemagick cli",
- "version": "0.1.2",
- "author": "Rasmus Andersson",
- "licenses": [{
- "type": "MIT"
- }],
- "repository": {
- "type": "git",
- "url": "http://github.com/rsms/node-imagemagick.git"
- },
- "engine": [ "node >=0.1.90" ],
- "main": "imagemagick"
+{ "name" : "imagemagick"
+, "description" : "A wrapper around the imagemagick cli"
+, "version" : "0.1.3"
+, "author" : "Rasmus Andersson <http://rsms.me/>"
+, "licenses" : ["MIT"]
+, "repository" : { "type" : "git"
+ , "url" : "http://github.com/rsms/node-imagemagick.git" }
+, "engine" : ["node >=0.6"]
+, "main" : "imagemagick"
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -1,42 +1,35 @@
-var sys = require('sys'),
- fs = require('fs'),
+var fs = require('fs'),
im = require('./imagemagick');
-var path = 'img.jpg';
-var timeStarted = new Date;
+var path = __dirname+'/sample-images/blue-bottle-coffee.jpg';
-im.crop({
- srcPath: path,
- dstPath: './cropped.jpg',
- width: 2000,
- height: 900,
- quality: 1
-}, function(err, stdout, stderr){
- if (err) return sys.error(err.stack || err);
-
- sys.puts('real time taken for convert: ' + (new Date() - timeStarted) + ' ms')
-
- im.identify(['-format', '%b', 'cropped.jpg'], function(err, r){
- if (err) throw err;
- sys.puts('size: ' + r.substr(0, r.length-2) + ' Bytes');
- })
-})
+(function () {
+ var opt, timeStarted = new Date;
+ im.crop(opt = {
+ srcPath: path,
+ dstPath: 'cropped.jpg',
+ width: 200,
+ height: 90,
+ quality: 1
+ }, function (err, stdout, stderr){
+ if (err) return console.error(err.stack || err);
+ console.log('crop(',opt,') ->', stdout);
+ console.log('Real time spent: '+(new Date() - timeStarted) + ' ms');
+ });
+})();
-
-im.crop({
- srcPath: path,
- dstPath: './cropped2.jpg',
- width: 2000,
- height: 900,
- gravity: "North",
- quality: 1
-}, function(err, stdout, stderr){
- if (err) return sys.error(err.stack || err);
-
- sys.puts('real time taken for convert: ' + (new Date() - timeStarted) + ' ms')
-
- im.identify(['-format', '%b', 'cropped2.jpg'], function(err, r){
- if (err) throw err;
- sys.puts('size: ' + r.substr(0, r.length-2) + ' Bytes');
- })
-})
+(function () {
+ var opt, timeStarted = new Date;
+ im.crop(opt = {
+ srcPath: path,
+ dstPath: 'cropped2.jpg',
+ width: 200,
+ height: 90,
+ gravity: "North",
+ quality: 1
+ }, function (err, stdout, stderr){
+ if (err) return console.error(err.stack || err);
+ console.log('crop(',opt,') ->', stdout);
+ console.log('Real time spent: '+(new Date() - timeStarted) + ' ms');
+ });
+})();
View
@@ -1,51 +1,52 @@
-var sys = require('sys'),
- fs = require('fs'),
+var fs = require('fs'),
im = require('./imagemagick');
-var path = 'sample-images/jpeg5.jpg';
+var path = __dirname+'/sample-images/blue-bottle-coffee.jpg';
var imdata = fs.readFileSync(path, 'binary');
-im.identify(path, function(err, features){
- if (err) return sys.error(err.stack || err);
- sys.puts('features: '+sys.inspect(features));
+im.identify(path, function (err, features){
+ if (err) return console.error(err.stack || err);
+ console.log('identify(path) ->', features);
})
-im.identify({data:imdata}, function(err, features){
- if (err) return sys.error(err.stack || err);
- sys.puts('features: '+sys.inspect(features));
+im.identify({data:imdata}, function (err, features){
+ if (err) return console.error(err.stack || err);
+ console.log('identify({data:imdata}) ->', features);
})
-im.readMetadata(path, function(err, metadata){
- if (err) return sys.error(err.stack || err);
- sys.puts('metadata: '+sys.inspect(metadata));
+im.readMetadata(path, function (err, metadata){
+ if (err) return console.error(err.stack || err);
+ console.log('readMetadata(path) ->', metadata);
})
-im.readMetadata({data:imdata}, function(err, metadata){
- if (err) return sys.error(err.stack || err);
- sys.puts('metadata: '+sys.inspect(metadata));
+im.readMetadata({data:imdata}, function (err, metadata){
+ if (err) return console.error(err.stack || err);
+ console.log('readMetadata({data:imdata} ->', metadata);
})
var timeStarted = new Date;
im.resize({
srcPath: path,
- dstPath: path+'.resized.jpg',
+ dstPath: 'test-resized.jpg',
width: 256
-}, function(err, stdout, stderr){
- if (err) return sys.error(err.stack || err);
- sys.puts('real time taken for convert: '+((new Date)-timeStarted)+' ms')
- im.identify(['-format', '%b', path+'.resized.jpg'], function(err, r){
+}, function (err, stdout, stderr){
+ if (err) return console.error(err.stack || err);
+ console.log('resize(...) wrote "test-resized.jpg"');
+ console.log('real time taken for convert: '+((new Date)-timeStarted)+' ms');
+ im.identify(['-format', '%b', 'test-resized.jpg'], function (err, r){
if (err) throw err;
- sys.puts('size: '+r.substr(0,r.length-2)+' Bytes');
+ console.log("identify(['-format', '%b', 'test-resized.jpg']) ->", r);
})
})
timeStarted = new Date;
im.resize({
srcData: imdata,
width: 256
-}, function(err, stdout, stderr){
- if (err) return sys.error(err.stack || err);
- sys.puts('real time taken for convert (with buffers): '+((new Date)-timeStarted)+' ms');
- fs.writeFileSync(path+'.resized-io.jpg', stdout, 'binary');
- sys.puts('size: '+stdout.length+' Bytes');
+}, function (err, stdout, stderr){
+ if (err) return console.error(err.stack || err);
+ console.log('real time taken for convert (with buffers): '+
+ ((new Date)-timeStarted)+' ms');
+ fs.writeFileSync('test-resized-io.jpg', stdout, 'binary');
+ console.log('resize(...) wrote "test-resized.jpg" ('+stdout.length+' Bytes)');
})

0 comments on commit 34c8deb

Please sign in to comment.