Skip to content

Commit

Permalink
Add an optional callback to imageDataToPNG
Browse files Browse the repository at this point in the history
  • Loading branch information
jsantell committed Feb 18, 2012
1 parent 9a31028 commit 4d987dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
Expand Down
9 changes: 4 additions & 5 deletions js/imagediff.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down

0 comments on commit 4d987dc

Please sign in to comment.