0

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.

2
  • I don't believe BZIP is a valid TIFF compression type - try LZW. Commented Apr 4, 2018 at 13:15
  • Other options appear to be FAX, GROUP4, JPEG, REL or ZIP so maybe try those for your scenario too. Commented Apr 4, 2018 at 13:22

1 Answer 1

1

You can list all compression options using:

identify -list compress 

Sample Output

B44 B44A BZip DXT1 DXT3 DXT5 Fax Group4 JBIG1 JBIG2 JPEG JPEG2000 Lossless LosslessJPEG LZMA LZW None Piz Pxr24 RLE Zip RunlengthEncoded ZipS 

If you pipe that into tiffdump you can see which ones result in a value other than 1 in the TIFF tags:

for f in $(identify -list compress); do echo $f convert -size 1024x768 xc:red +noise random -compress $f a.tif tiffdump a.tif | grep -i "^Compression" done B44 Compression (259) SHORT (3) 1<1> B44A Compression (259) SHORT (3) 1<1> BZip Compression (259) SHORT (3) 1<1> DXT1 Compression (259) SHORT (3) 1<1> DXT3 Compression (259) SHORT (3) 1<1> DXT5 Compression (259) SHORT (3) 1<1> Fax Compression (259) SHORT (3) 1<3> Group4 Compression (259) SHORT (3) 1<4> JBIG1 convert: CompressionNotSupported `JBIG1' @ error/tiff.c/WriteTIFFImage/3590. Compression (259) SHORT (3) 1<1> JBIG2 Compression (259) SHORT (3) 1<1> JPEG Compression (259) SHORT (3) 1<7> JPEG2000 Compression (259) SHORT (3) 1<1> Lossless Compression (259) SHORT (3) 1<1> LosslessJPEG Compression (259) SHORT (3) 1<1> LZMA convert: CompressionNotSupported `LZMA' @ error/tiff.c/WriteTIFFImage/3590. Compression (259) SHORT (3) 1<1> LZW Compression (259) SHORT (3) 1<5> None Compression (259) SHORT (3) 1<1> Piz Compression (259) SHORT (3) 1<1> Pxr24 Compression (259) SHORT (3) 1<1> RLE Compression (259) SHORT (3) 1<32773> Zip Compression (259) SHORT (3) 1<8> RunlengthEncoded Compression (259) SHORT (3) 1<32773> ZipS Compression (259) SHORT (3) 1<1> 

Which implies, to me, in my environment at least, that the only valid compression types for TIFF with ImageMagick are:

FAX, GROUP4, JPEG, RLE, LZW or ZIP 

Also, -monochrome as well as -normalize seems superfluous to me, since the former means "only use blacks and whites", and the latter means "stretch the range of pixels to the limits of black and white".


Also, have a look at Wikipedia and as far as I can see, BZIP is not mentioned there either.

Sign up to request clarification or add additional context in comments.

4 Comments

I appreciate the thoroughness of this reply. I followed your steps and found the same compression types you did, but they all threw the same error.
I also removed -monochrome from my args. I appreciate the explanation on the similarities of those processes.
Maybe try the same command at the commandline in a Command Prompt and see if there is an error. Also try checking what compression gets used in the output file magick identify -verbose OUTPUT.TIF | FINDSTR /I compress or somesuch under Windows.
I did try it from Powershell, and it worked without issue. I ended up writing a Powershell script to handle the entire batch. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.