Use less space when converting many images into a pdf file?

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
Tim
Posts: 14
Joined: 2014-11-15T12:39:34-07:00
Authentication code: 6789

Use less space when converting many images into a pdf file?

Post by Tim »

I have about 250 image files (png and jpg) in a directory. I use the command convert them into a pdf file:

Code: Select all

convert * my.pdf
It takes about 10GB (at peak) and 4 hours to create a 80MB pdf file.

I firstly failed to run it, because I don't have enough free space in my "/tmp" (actually in my "/" partition). Then I had to find a external hdd with abundant free space, and set the environment variable TMPDIR to point to it, and then succeeded.

But I wonder if there is some way to reduce the peak space used by "convert", so to eliminate the need for an external hdd?

For more information, each image has 2500 x 3080 pixels, and about 500KB.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Use less space when converting many images into a pdf file?

Post by snibgo »

IM first reads all the images into memory. If using Q16, this needs 8 bytes/pixel for each image. 2500*3080*250*8/1e9 = 15.5 GB.

Q8 would need half the memory.
snibgo's IM pages: im.snibgo.com
Tim
Posts: 14
Joined: 2014-11-15T12:39:34-07:00
Authentication code: 6789

Re: Use less space when converting many images into a pdf file?

Post by Tim »

snibgo wrote:IM first reads all the images into memory. If using Q16, this needs 8 bytes/pixel for each image. 2500*3080*250*8/1e9 = 15.5 GB.

Q8 would need half the memory.
Thanks.

What are Q16 and Q8?

Is there other bad effect using Q8?

How can I use Q8? My OS is Ubuntu, and I installed Imagick from its repository.
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

Re: Use less space when converting many images into a pdf file?

Post by pipitas »

Tim wrote:I have about 250 image files (png and jpg) in a directory. I use the command convert them into a pdf file:

Code: Select all

convert * my.pdf
It takes about 10GB (at peak) and 4 hours to create a 80MB pdf file.

I firstly failed to run it, because I don't have enough free space in my "/tmp" (actually in my "/" partition). Then I had to find a external hdd with abundant free space, and set the environment variable TMPDIR to point to it, and then succeeded.

But I wonder if there is some way to reduce the peak space used by "convert", so to eliminate the need for an external hdd?

For more information, each image has 2500 x 3080 pixels, and about 500KB.
In this case, the following approach should be way faster, use much less memory, and produce roughly the same results:

Code: Select all

for i in *.png; do convert ${i} ${i/.png/.pdf}; done
for i in *.jpg; do convert ${i} ${i/.jpg/.pdf}; done
for i in *.jpeg; do convert ${i} ${i/.jpeg/.pdf}; done   # maybe not needed

pdftk *.pdf cat output all-pdfs.pdf
Note, that if the order of PDF pages is important to you: you'll have to list them on the pdftk command line as you need them. My command will use them in alphabetical order (but yours did the same).
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

Re: Use less space when converting many images into a pdf file?

Post by pipitas »

snibgo wrote:IM first reads all the images into memory. If using Q16, this needs 8 bytes/pixel for each image. 2500*3080*250*8/1e9 = 15.5 GB.

Q8 would need half the memory.
Since Tim very likely does not have that much free memory available, the system started to swap -- which explains why it took so long to complete the conversion.
Post Reply