Browse files

Add an optional callback to imageDataToPNG

  • Loading branch information...
1 parent 9a31028 commit 4d987dc76e104ab2da7b8d1ba2a0d074daa02a56 @jsantell jsantell committed Feb 17, 2012
Showing with 5 additions and 6 deletions.
  1. +1 −1 README.md
  2. +4 −5 js/imagediff.js
View
2 README.md
@@ -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
9 js/imagediff.js
@@ -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);
}

0 comments on commit 4d987dc

Please sign in to comment.