Tiff to JBIG2 PDF?

A place where ImageMagick may be discussed.

Tiff to JBIG2 PDF?

Postby dowcet » Fri Mar 13, 2020 11:51 am

I have a bunch of scanned monochrome images like this:

Code: Select all
input.tif TIFF 3184x5276 3184x5276+0+0 1-bit Bilevel DirectClass 104KB 0.000u 0:00.000

I want to make a PDF which will not be so large. From what I understand JBIG2 compression is the best available for monochrome PDFs. So I tried this:

Code: Select all
convert input.tif -compress JBIG2 -density 300 output.pdf

Despite the much lower resolution, the resulting file is actually a little bit larger (and 16-bit):

Code: Select all
output.pdf PDF 764x1266 764x1266+0+0 16-bit Bilevel DirectClass 122KB 0.010u 0:00.010

What am I doing wrong?
dowcet
 

Re: Tiff to JBIG2 PDF?

Postby snibgo » Fri Mar 13, 2020 11:56 am

I don't know much about compression within PDF files. You might try all the "-compress" options to see which is the best.
snibgo
 

Re: Tiff to JBIG2 PDF?

Postby dowcet » Fri Mar 13, 2020 12:08 pm

@snibgo: Thanks, that is a great suggestion.

I started off with a black/white PNG called bilevel-image.png

identify -verbose bilevel-image.png

Image: bilevel-image.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: PseudoClass
Geometry: 3100x4746+0+0
Units: Undefined
Colorspace: Gray
Type: Bilevel
Base type: Undefined
Endianess: Undefined
Depth: 8/1-bit
Channel depth:
gray: 1-bit
Colors: 2
Compression: Zip

I produced all the PDFs with the command:

for a in $(convert -list compress); do convert -compress $a bilevel-image.png bilevel-image-$a.pdf; done

and then checked the compression used by the PDF and added the PDF's size for comparison.

Code: Select all
B44A          /RunLengthDecode    757266
B44           /RunLengthDecode    757264
BZip          /RunLengthDecode    757266
DXT1          /RunLengthDecode    757266
DXT3          /RunLengthDecode    757266
DXT5          /RunLengthDecode    757266
Fax           /CCITTFaxDecode      98604
Group4        /CCITTFaxDecode      98610
JBIG1         /RunLengthDecode    757268
JBIG2         /RunLengthDecode    757268
JPEG2000      /JPXDecode         2067778
JPEG          /DCTDecode         2436412
LosslessJPEG  /RunLengthDecode    757282
Lossless      /RunLengthDecode    757274
LZMA          /RunLengthDecode    757266
LZW           /LZWDecode          325225
None          /ASCII85Decode    17038912
Piz           /RunLengthDecode    757264
Pxr24         /RunLengthDecode    757268
RLE           /RunLengthDecode    757264
RunlengthEncoded /RunLengthDecode 757290
WebP          /RunLengthDecode    757266
ZipS          /RunLengthDecode    757266
Zip           /FlateDecode        311026
Zstd          /RunLengthDecode    757266

/RunLengthDecode is clearly the default, used when the desired compression cannot be.

JBIG2 /RunLengthDecode 757268

probably means that the JBIG2 libraries are not available.

Generally JBIG2 gives by far the best bilevel compression.
dowcet
 


Return to Questions concerning ImageMagick

Who is online

Users browsing this forum: No registered users and 1 guest

cron