Created
November 5, 2012 18:16
-
-
Save johntitus/4019396 to your computer and use it in GitHub Desktop.
(Node.js) Watermark an image using ImageMagick from two streams.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Dependencies | |
*/ | |
var fs = require('fs'), | |
request = require('request'), | |
cp = require('child_process'), | |
spawn = cp.spawn; | |
var image = request("http://medpreps.com/wp-content/uploads/2012/05/cma-practice-test.jpg"); | |
var wm = request("https://github.com/linse/Gibberbot/diff_blob/f096f6d94b3fb745975ea5f61f5a43b47098598b/res/drawable/droid_watermark.png?raw=true"); | |
// Composite is one of the file that make up image magick. | |
// The second argument, `+200+200` represent the location on the image where to put the watermark (x,y from top left). | |
var args = ['-geometry', '+200+200', 'wmPipe', 'basePipe', '-']; | |
var composite = spawn('composite', args); | |
/* | |
* basePipe and wmPipe are two name unix pipes. You can create one with `mkfifo basePipe && chmod 777 basePipe` | |
*/ | |
image.pipe(fs.createWriteStream("./basePipe")); | |
wm.pipe(fs.createWriteStream("./wmPipe")); | |
// Pipe the image magick output to a file. Could just as easily pipe it to a http response or any other stream. | |
composite.stdout.pipe( fs.createWriteStream("out.jpg") ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
?