memory and cpu usage in pdf to tiff for fax conversion

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
kgc
Posts: 6
Joined: 2011-11-17T17:53:58-07:00
Authentication code: 8675308

memory and cpu usage in pdf to tiff for fax conversion

Post by kgc »

Limiting memory usage by IM is a popular topic but I haven't been able to find out if what I'm looking for is possible.
After some trial and error the following convert arguments produce fairly good results for the fax, however, the memory used, and time it takes, well, it's fairly ridiculous! (Several gigs for a couple of pages?!)

Code: Select all

convert -normalize  -density 204x196 -resize 1728x2156\! -black-threshold 30 \
  -compress Fax -units PixelsPer Inch $input $output
I've had success limiting memory usage with the -limit directives but the increased processing time due to using temp files in place is substantial.

A colleague mentioned that he thought there were ways to tell IM to sacrifice the quality of certain operations to reduce memory usage and processing time which would be ideal for this application. Is this the case, and if so, any suggestions how?

Thanks.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: memory and cpu usage in pdf to tiff for fax conversion

Post by magick »

ImageMagick stores images in RGBA format (consumes 4 channels per pixel) even for black and white images. ImageMagick 7.0.0, which is in development, will only use 1 channel instead of 4 for black and white images. Unfortunately it is not completely implemented just yet. An alternative is to use the Q8 version of ImageMagick (1 byte per pixel component) instead of the Q16 (default build of 2 bytes per pixel component). The Q8 version reduces the memory requirements by 1/2.
kgc
Posts: 6
Joined: 2011-11-17T17:53:58-07:00
Authentication code: 8675308

Re: memory and cpu usage in pdf to tiff for fax conversion

Post by kgc »

q8 is a compile time option?
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: memory and cpu usage in pdf to tiff for fax conversion

Post by glennrp »

kgc wrote:q8 is a compile time option?
It's a configure-time option; put

Code: Select all

--with-quantum-depth=8
on your configure command.
kgc
Posts: 6
Joined: 2011-11-17T17:53:58-07:00
Authentication code: 8675308

Re: memory and cpu usage in pdf to tiff for fax conversion

Post by kgc »

The q8 version is a substantial improvement over the default q16.

Thanks!
kgc
Posts: 6
Joined: 2011-11-17T17:53:58-07:00
Authentication code: 8675308

Re: memory and cpu usage in pdf to tiff for fax conversion

Post by kgc »

I spoke too soon. The q8 version is substantially faster but, with at least one test pdf, is producing an all black page where the original version of IM was producing a reasonable quality tiff for faxing.

I was originally working with ImageMagick-6.5.4.7-5.el6 (dist. rpm for RHEL/Scientific Linux 6x x86_64), and upgraded to 6.7.3-7. Compile options for 6.7.3-7 based off the dist's rpm.

Code: Select all

./configure --enable-shared --disable-static --with-quantum-depth=8 --with-modules  --with-x --with-threads \
            --with-magick_plus_plus --with-gslib --with-wmf --with-lcms --with-rsvg --with-xml  --without-dps --prefix=/opt/imagemagick-q8-6.7.3-7 
In both cases, the pdf is converted with the following arguments.

Code: Select all

convert -normalize  -density 204x196 -resize 1728x2156\! -black-threshold 30 -compress Fax -units PixelsPerInch in.pdf out.tiff
Original test pdf http://kgc.members.sonic.net/test.pdf
Output from dist's IM rpm http://kgc.members.sonic.net/orig.tiff
Output from q8 compiled from source http://kgc.members.sonic.net/new.tiff

Any suggestions?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: memory and cpu usage in pdf to tiff for fax conversion

Post by fmw42 »

try the following with formal IM 6 syntax and see if that helps see http://www.imagemagick.org/Usage/basics/#why

convert -density 204x196 -units PixelsPerInch in.pdf -normalize -resize 1728x2156\! -black-threshold 30 -compress Fax out.tiff


Note your problem is likely with -black-threshold 30

In Q16 that is 30 out of 65535. In Q8 it is 30 out of 255. You would be better using percent values than raw values.
kgc
Posts: 6
Joined: 2011-11-17T17:53:58-07:00
Authentication code: 8675308

Re: memory and cpu usage in pdf to tiff for fax conversion

Post by kgc »

There's no apparent change in the output either by reordering arguments as suggested or eliminating the normalize or black-threshold.

It looks like the new version is getting a transparent png back from gs, where the old version was getting a raw pnm -- the problem appears that the new version is filling the transparent png with black.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: memory and cpu usage in pdf to tiff for fax conversion

Post by fmw42 »

you may need to edit your delegates.xml to change the device for pdf between pngalpha and pnmraw

the former allow transparency but not multiple pages and the latter allows multiple pages but not transparency


have you tried

convert -density 204x196 -units PixelsPerInch in.pdf -auto-level -resize 1728x2156\! -compress Fax out.tiff

or

convert -density 204x196 -units PixelsPerInch in.pdf -resize 1728x2156\! -monochrome -compress Fax out.tiff

what happens if you remove the -compress Fax
kgc
Posts: 6
Joined: 2011-11-17T17:53:58-07:00
Authentication code: 8675308

Re: memory and cpu usage in pdf to tiff for fax conversion

Post by kgc »

Turning off fax compression generates as transparent tiff, the other options had no affect. Turning alpha off appears to produce the desired results but this really seems like a bug, or at least, really not DWIM.

convert -density 204x196 -units PixelsPerInch in.pdf -alpha off -resize 1728x2156\! -compress Fax out4.tiff
Post Reply