Skip to content
Browse files

add async example and update old example to use the new encodeSync fu…

…nction
  • Loading branch information...
1 parent 0a65599 commit 47b2af14e180823cd9583100583451491e93cc68 @pkrumins committed
Showing with 30 additions and 1 deletion.
  1. +29 −0 examples/fixed-jpeg-stack-async.js
  2. +1 −1 examples/fixed-jpeg-stack.js
View
29 examples/fixed-jpeg-stack-async.js
@@ -0,0 +1,29 @@
+var JpegLib = require('jpeg');
+var fs = require('fs');
+var sys = require('sys');
+var Buffer = require('buffer').Buffer;
+
+var jpegStack = new JpegLib.FixedJpegStack(720, 400, 'rgba');
+
+function rectDim(fileName) {
+ var m = fileName.match(/^\d+-rgba-(\d+)-(\d+)-(\d+)-(\d+).dat$/);
+ var dim = [m[1], m[2], m[3], m[4]].map(function (n) {
+ return parseInt(n, 10);
+ });
+ return { x: dim[0], y: dim[1], w: dim[2], h: dim[3] }
+}
+
+var files = fs.readdirSync('./push-data');
+
+files.forEach(function(file) {
+ var dim = rectDim(file);
+ var rgba = fs.readFileSync('./push-data/' + file, 'binary');
+ var buf = new Buffer(rgba.length);
+ buf.write(rgba, 'binary');
+ jpegStack.push(buf, dim.x, dim.y, dim.w, dim.h);
+});
+
+jpegStack.encode(function (image) {
+ fs.writeFileSync('fixed-async.jpg', image, 'binary');
+});
+
View
2 examples/fixed-jpeg-stack.js
@@ -23,5 +23,5 @@ files.forEach(function(file) {
jpegStack.push(buf, dim.x, dim.y, dim.w, dim.h);
});
-fs.writeFileSync('fixed.jpg', jpegStack.encode(), 'binary');
+fs.writeFileSync('fixed.jpg', jpegStack.encodeSync(), 'binary');

0 comments on commit 47b2af1

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