Page 1 of 1

How do I minimize IM's PDF output size?

Posted: 2008-08-27T08:00:32-07:00
by silenceseeker
I am trying to convert a JPG image to PDF, using convert:
convert lettersizepage_at_300_dpi.jpg lettersizepage_at_300_dpi.jpg.pdf
It successfully converts that JPG image to a single page PDF file, but that PDF file has a HUGE size...

The input JPG file is about 1MB in size. The output PDF is 20MB in size!

I tried using the '-compress JPEG' option but that didn't help a bit. :(

Is there a way to reduce ImageMagick's PDF output to a sane size?

I am aware of the image quality tradeoff - I only need an image of about the same quality of the original JPG file.

>>>>>>>>>>>>>>>>>> Update: I just tested this again and I got baffling results:

On my home Linux box, running ImageMagick 6.2.2 05/24/06 Q16, the output PDF file size is about the same as the input JPG.

But on my web host's (Linux) server, running ImageMagick 6.4.2 06/27/08 Q16, the output PDF files is about 20X larger than the same input JPG!

This is using the same exact command and JPG input file!

What could explain this?

Is it possible that the web host configured ImageMagick so that it does not compress? Is it possible at all to maim ImageMagick like this?


Thanks :)

Re: How do I minimize IM's PDF output size?

Posted: 2008-08-27T10:30:06-07:00
by fmw42
I have noticed that IM PDF files are much larger than other applications. But I suspect IM relies upon ghostscript to handle this and so may be out of IM control. I would be interested in hearing what the IM folks have to say, also.

Re: How do I minimize IM's PDF output size?

Posted: 2008-08-27T11:02:12-07:00
by magick
Using the latest ImageMagick release:
  • -> convert logo: logo.jpg

    -> convert logo.jpg logo.pdf

    -> ls -l logo.jpg logo.pdf

    -rw------- 1 magick magick 33572 2008-08-27 14:00 logo.jpg
    -rw------- 1 magick magick 274216 2008-08-27 14:00 logo.pdf

    -> convert logo.jpg -compress jpeg logo.pdf

    -> ls -l logo.jpg logo.pdf

    -rw------- 1 magick magick 33572 2008-08-27 14:00 logo.jpg
    -rw------- 1 magick magick 37317 2008-08-27 14:00 logo.pdf

Re: How do I minimize IM's PDF output size?

Posted: 2008-08-27T11:24:38-07:00
by silenceseeker
Magick, thank you very much for your quick answer. I hope that you noticed in my original posting that I, too, was able to convert from JPG to PDF, keeping the file size to about the same.

However, what I also described there is that on a different system (my web host's, on which I don't have a root account, only a jailshell, ImageMagick behaves differently (as described above).

So, my question remains: Is it possible that the web host configured ImageMagick so that it does not compress? Is it possible at all, for a system administrator, to cripple ImageMagick like this?

Thank you!

Re: How do I minimize IM's PDF output size?

Posted: 2008-08-27T16:06:43-07:00
by rmagick
It seems more likely that your web host is using an older version of ImageMagick. You can use this command to find out what version is installed.

Code: Select all

convert -version

Re: How do I minimize IM's PDF output size?

Posted: 2008-08-27T17:04:05-07:00
by silenceseeker
rmagick wrote:It seems more likely that your web host is using an older version of ImageMagick.
Thanks for your tip. However, as I mentioned in my original posting, my web host is actually using a newer version than the one on my Fedora Core 4 Linux box (and which is working beautifully). My web host is running ImageMagick 6.4.2 06/27/08 Q16.

Any ideas what could be going wrong?

At some point I thought that perhaps my web host (shared hosting) intentionally configured ImageMagick this way, so that users will not use the "resource intensive" (as web hosts like to put it) compression.

But then I checked and saw that compression for .JPG or .PNG is enabled in that web host's ImageMagick. Compression is not working only for the PDF format. Weird. :shock:

Re: How do I minimize IM's PDF output size?

Posted: 2008-10-11T14:17:22-07:00
by thzxcyl
Hello, I also have the same problem where jpg are not compressed when converted to pdf, resulting about 20X size than the original jpg. Both 6.4.4-Q16 and 6.4.1-Q16 have the same problem. Any idea how to fix this?

Many thanks!

Re: How do I minimize IM's PDF output size?

Posted: 2008-10-11T14:23:20-07:00
by thzxcyl
Oh, and I'm on a Windows box using the binaries from the imagemagick website. The static version does not detect the existence of gs on my computer (i.e. does not convert to pdf at all), and the dynamic version is giving me this:

~
$ /cygdrive/c/Program\ Files/ImageMagick-6.4.4-Q16/convert.exe logo: logo.jpg

~
$ /cygdrive/c/Program\ Files/ImageMagick-6.4.4-Q16/convert.exe logo.jpg logo.pdf

~
$ ls -l logo.*
-rwxrwxrwx 1 user None 33572 Oct 11 17:20 logo.jpg
-rwxrwxrwx 1 user None 274209 Oct 11 17:20 logo.pdf

(yeah it is cygwin bash shell, but my im is not the cygwin version)

Thanks for the help!

Re: How do I minimize IM's PDF output size?

Posted: 2009-05-25T13:37:47-07:00
by m_stolle
Any update on this issue? The new version has made it into Ubuntu and it's really annoying. Old versions of ImageMagick would move the jpeg as a jpeg-compressed image into the PDF. New versions seem to re-raster, making for huge pdfs.

Martin

Re: How do I minimize IM's PDF output size?

Posted: 2009-05-25T13:45:19-07:00
by magick
We cannot reproduce the problem:
  • -> convert logo: -sharpen 0x1 logo.pdf
    -> ls -l logo.pdf
    -rw-r--r--. 1 cristy cristy 143297 2009-05-25 16:42 logo.pdf
    -> convert logo: -sharpen 0x1 -compress jpeg logo.pdf
    -> ls -l logo.pdf
    -rw-r--r--. 1 cristy cristy 53627 2009-05-25 16:42 logo.pdf
In logo.pdf we see
  • /Filter [ /DCTDecode ]
Which means the image is JPEG-compressed as expected.

Re: How do I minimize IM's PDF output size?

Posted: 2009-05-25T14:10:42-07:00
by m_stolle
Hm, appears that it must've been fixed then. It's not listed in the Changelog anywhere. I get the following:

mstoll@MartinVaioTX:~$ convert logo: -sharpen 0x1 logo.pdf
mstoll@MartinVaioTX:~$ ls -l logo.pdf
-rw-r--r-- 1 mstoll mstoll 263214 2009-05-25 23:03 logo.pdf
mstoll@MartinVaioTX:~$ strings logo.pdf | grep Filter
/Filter [ /RunLengthDecode ]
/Filter [ /RunLengthDecode ]
/Filter [ /RunLengthDecode ]

mstoll@MartinVaioTX:~$ convert --version
Version: ImageMagick 6.4.5 2009-01-22 Q16 OpenMP http://www.imagemagick.org

So somewhere between 6.4.5 and current, it must've been fixed. Oh well, too bad it wasn't fixed before Ubuntu 9.04 was frozen 8-(. I'll try compiling Ubuntu packages from Debian unstable (6.5.1) - hopefully that'll tie me over until Ubuntu 9.10.

Martin

Re: How do I minimize IM's PDF output size?

Posted: 2009-05-25T22:02:34-07:00
by anthony
Look at the table of compression methods and the PDF results in the raw notes on IM Exmaples
http://www.imagemagick.org/Usage/formats/#pdf

Re: How do I minimize IM's PDF output size?

Posted: 2009-05-25T22:52:24-07:00
by m_stolle
Hmm... thanks for the link to the notes. The -compress might have helped me with the older version of IM, however the 6.5.1 version from Debian unstable works out-of-the-box, so I venture it was a regression in IM, since jpg-to-pdf worked as expected in old versions and new versions - just not in-between. I had previously searched for documentation of -compress but not found it 8-/.

I still get a segfault when trying to convert multiple jpgs to a multipage pdf, but that's ok - I converted them one-by-one and then used pdfjoin from pdfjam to merge the pages.

Martin