const spawn = require('child_process').spawn; function readFromRegion(frame: Buffer, x: int, y: int, width: int, height: int) { const convert = spawn('convert', ['-', '-negate', '-crop', `${width}x${height}+${x}+${y}`, '-']) const result = new Buffer(512 * 1024) let resultSize = 0 convert.stdout.on('data', (data) => { if (data.length + resultSize > result.length) { // Buffer not big enough } else { resultSize += data.length data.copy(result) } }); convert.on('exit', (code) => { }); convert.stdin.write(frame) }