Permalink
Browse files

Merge branch 'node-js' of git://github.com/jsantell/js-imagediff

  • Loading branch information...
2 parents 79dcd18 + 408945b commit 76d48b36470a0313624fcf3f476601e1297f73c1 @cesutherland cesutherland committed Feb 18, 2012
Showing with 19 additions and 19 deletions.
  1. +1 −1 README.md
  2. +5 −4 bin/imagediff
  3. +4 −5 imagediff.js
  4. +1 −1 imagediff.min.js
  5. +4 −5 js/imagediff.js
  6. +4 −3 spec/ImageDiffSpec.js
View
@@ -17,7 +17,7 @@ API
* `equal(a, b)` tests image type objects for equality.
* `diff(a, b)` performs an image diff on a and b, returning a - b.
* `noConflict()` removes imagediff from the global space for compatibility, returning imagediff.
-* `imageDataToPNG(imageData, outputFile)` renders the imageData to png in outputFile. (Node only)
+* `imageDataToPNG(imageData, outputFile, (callback))` renders the imageData to png in outputFile, firing an optional callback upon save. (Node only)
Command Line
---
View
@@ -1,6 +1,7 @@
#!/usr/bin/env node
-var imagediff = require('imagediff'),
- Canvas = require('canvas');
+var
+ imagediff = require('../imagediff.js'),
+ Canvas = require('canvas');
commandLine(process.argv.slice(2));
@@ -47,9 +48,9 @@ function commandLine (args) {
result = imagediff[fn](a, b, t);
if (fn === 'equal') {
- process.stdout.write(result ? 'true' : 'false');
+ process.stdout.write(result ? 'true\n' : 'false\n');
} else if (fn === 'diff') {
imagediff.imageDataToPNG(result, output);
- process.stdout.write('Diff of ' + aName + ' and ' + bName + ' rendered to ' + output);
+ process.stdout.write('Diff of ' + aName + ' and ' + bName + ' rendered to ' + output + '\n');
}
};
View
@@ -314,19 +314,18 @@
// Image Output
- function imageDataToPNG (imageData, outputFile) {
+ function imageDataToPNG (imageData, outputFile, callback) {
var
canvas = toCanvas(imageData),
base64Data,
decodedImage;
+ callback = callback || Function;
+
base64Data = canvas.toDataURL().replace(/^data:image\/\w+;base64,/,"");
decodedImage = new Buffer(base64Data, 'base64');
- require('fs').writeFile(outputFile, decodedImage, function(E) {
- //TODO throws 'png' regardless of success?
- if (E) throw E;
- });
+ require('fs').writeFile(outputFile, decodedImage, callback);
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -314,19 +314,18 @@
// Image Output
- function imageDataToPNG (imageData, outputFile) {
+ function imageDataToPNG (imageData, outputFile, callback) {
var
canvas = toCanvas(imageData),
base64Data,
decodedImage;
+ callback = callback || Function;
+
base64Data = canvas.toDataURL().replace(/^data:image\/\w+;base64,/,"");
decodedImage = new Buffer(base64Data, 'base64');
- require('fs').writeFile(outputFile, decodedImage, function(E) {
- //TODO throws 'png' regardless of success?
- if (E) throw E;
- });
+ require('fs').writeFile(outputFile, decodedImage, callback);
}
View
@@ -452,13 +452,14 @@ describe('ImageUtils', function() {
context.drawImage(image, 0, 0);
imageData = context.getImageData(0, 0, image.width, image.height);
- imagediff.imageDataToPNG(imageData, output);
+ imagediff.imageDataToPNG(imageData, output, function() {
+ oImage.src = output;
+ });
});
- oImage.src = output;
waitsFor(function () {
return oImage.complete;
- }, 'image not loaded.', 5000);
+ }, 'image not loaded.', 2000);
runs(function () {
oImageData = imagediff.toImageData(oImage);

0 comments on commit 76d48b3

Please sign in to comment.