Page 1 of 1

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

Posted: 2014-11-15T12:48:20-07:00
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.

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

Posted: 2014-11-15T13:12:13-07:00
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.

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

Posted: 2014-11-15T13:18:33-07:00
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.

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

Posted: 2014-11-15T14:17:33-07:00
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).

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

Posted: 2014-11-15T14:21:53-07:00
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.