Last active
February 18, 2020 12:16
-
-
Save wmakeev/34c5b77f0cc01f7860062361bf12a669 to your computer and use it in GitHub Desktop.
Imagemagick pipes #imagemagick #pipe
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
const fs = require('fs') | |
const path = require('path') | |
const spawn = require('child_process').spawn | |
// Gradient overlay example | |
// http://www.imagemagick.org/script/command-line-processing.php#input | |
const photoWriteStream = fs.createWriteStream( | |
path.join(__dirname, '/img-02-js-out.jpg') | |
) | |
const photoReadStream = fs.createReadStream(path.join(__dirname, 'img-02.jpg')) | |
const gradientChildProcess = spawn('convert', [ | |
'-size', | |
'1500x120', | |
'gradient:', | |
'miff:-' | |
]) | |
const convertChildProcess = spawn( | |
// 'magick', | |
'convert', | |
[ | |
'jpg:-', | |
'fd:3', | |
'-gravity', | |
'South', | |
'-alpha', | |
'off', | |
'-compose', | |
'CopyOpacity', | |
'-composite', | |
'-background', | |
'white', | |
'-alpha', | |
'remove', | |
'jpg:-' | |
], | |
{ | |
stdio: ['pipe', 'pipe', 2, 'pipe'] // 2 - share stderr | |
} | |
) | |
photoReadStream.pipe(convertChildProcess.stdin) | |
gradientChildProcess.stdout.pipe(convertChildProcess.stdio[3]) | |
convertChildProcess.stdout.pipe(photoWriteStream) |
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
var fs = require('fs') | |
var spawn = require('child_process').spawn | |
var request = require('request') | |
var photoStream1 = request('http://www.imagemagick.org/image/wizard.jpg') | |
var outFileStream = fs.createWriteStream(__dirname + '/temp-convert.jpg') | |
var convert = spawn('convert', ['-', '-append', '-'], { | |
stdio: ['pipe', 'pipe', 2] | |
}) | |
photoStream1.pipe(convert.stdin) | |
convert.stdout.pipe(outFileStream) | |
// OK | |
// temp-convert.jpg contains image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment