Browse files

A little script that outputs PNGs as data urls.

  • Loading branch information...
1 parent bf6937d commit d471513dec2782c1a6caafae0720336f85615909 @simonwex simonwex committed Jun 28, 2012
Showing with 26 additions and 0 deletions.
  1. +26 −0 bin/png2data.js
View
26 bin/png2data.js
@@ -0,0 +1,26 @@
+#!/usr/bin/env node
+
+var
+fs = require('fs'),
+path = require('path');
+
+
+function displayUsageAndQuit(){
+ console.log(process.argv);
+ var execPath = "./" + path.relative(process.cwd(), __filename);
+
+ console.log("Usage (OS X):\n\t" + execPath + " <path to png> | pbcopy");
+
+ process.exit(0);
+}
+
+if (process.argv.length != 3){
+ displayUsageAndQuit();
+}
+
+
+var filePath = process.argv.pop();
+
+var buffer = fs.readFileSync(filePath);
+process.stdout.write('data:image/png;base64,');
+process.stdout.write(buffer.toString('base64'));

0 comments on commit d471513

Please sign in to comment.