I'm trying to use ImageMagick command line to compress TIFF files by spawning child processes from node. Certain commands cause no issue, such as monochrome and despeckling.
let tiff2png = spawn('C:\\Program Files\\ImageMagick-7.0.7-Q8\\convert.exe', [ path, '-monochrome', '-normalize', '-despeckle', targetPath]); This raises no errors, but outputs TIFF files of 17MB when the source files are around 2.5MB. I've tried adding
-compress BZip to my args both prior to saving to the targetPath and iterating over the targetPaths after they've been converted. Both attempts log out buffer errors from the following event watcher:
tiff2png.stderr.on('data', (data: any) => { console.log('stderr: ', JSON.stringify(data)); }); I've stringified the error in order to expand the error object, hoping to see some useful details. The full error just contains a type of "Buffer" and a uselss array of numbers:
stderr: {"type":"Buffer","data":[99,111,110,118,101,114,116,46,101,120,101,58,32,117,110,114,101,99,111,103,110,105,122,101,100,32,111,112,116,105,111,110,32,96,45,99,111,109,112,114,101,115,115,32,66,90,105,112,39,32,64,32,101,114,114,111,114,47,99,111,110,118,101,114,116,46,99,47,67,111,110,118,101,114,116,73,109,97,103,101,67,111,109,109,97,110,100,47,49,50,51,57,46,13,10]} Certain other ImageMagick commands throw the same error, such as -contrast-stretch and -level. This is the last element of a project, and I've been trying to get it to work for the last two days. This is on a 64-bit Win10 Ultimate machine, hence the Windows pathing in the commands.
I've tried wrapping the output in a writeFileSync, but with no success. I have a feeling that this is a file streaming issue, but I can't discern the exact nature. I'd be grateful if anyone could help me find details about the error or a solution.
BZIPis a valid TIFF compression type - tryLZW.FAX,GROUP4,JPEG,RELorZIPso maybe try those for your scenario too.