in reply to Size problem of pdf file using ImageMagick

pdf output can be compressed in different ways. Newer versions of ImageMagick seem to reraster the image instead of just embedding the original jpg, and then output it without compression. Try to use compression method jpeg for the output and quality level 75%

As you say, your images are line drawings, you may also prefer to reduce number of colors to 2 (black and white) and then save them using some lossless compression scheme instead (LZW etc) instead of jpeg

Maybe you also would like to switch to graphicsmagick instead, (also provides Perl bindings) the default settings of which I generally prefer (in particular w.r.t. filesize, without visibly compromising quality)

  • Comment on Re: Size problem of pdf file using ImageMagick

Replies are listed 'Best First'.
Re^2: Size problem of pdf file using ImageMagick
by merrymonk (Hermit) on Dec 24, 2015 at 15:23 UTC
    I have obtained these images by scanning the drawings in just two colours.
    I see your comments about the alternate graphicsmagick but I would prefer to stick with imagemagick.
    Using comments from both replies I altered the Perl so that the jpg and pdf were saved as before and then saved again using LZW compression and a quality of 75. This gave four files. The code follows
    $mod_file_name = $file_name_jpg; $mod_dp = '-' . $jv . 'pc.'; # normal $mod_file_name =~ s/\./$mod_dp/; $rc = $img_copy->Write($dir_name . '\\' . $mod_file_name); $mod_file_name =~ s/jpg/pdf/; $rc = $img_copy->Write($dir_name . '\\' . $mod_file_name); # compressed $mod_file_name = $file_name_jpg; $mod_dp = '-' . $jv . 'pc-compressed.'; $mod_file_name =~ s/\./$mod_dp/; $rc = $img_copy->Write(filename => $dir_name . '\\' . $mod_file_name, +compression => 'LZW', quality => 75); $mod_file_name =~ s/jpg/pdf/; $rc = $img_copy->Write(filename => $dir_name . '\\' . $mod_file_name, +compression => 'LZW', quality => 75);
    For one jpg file I obtained the four files for:
    1. The original jpg file
    2. After using Scale to reduce the size of the image by 2 (in x and y)
    The file sizes were for full size
    jpg 1,099 kb
    pdf 1,331 kb
    jpg compressed 742 kb
    pdf compressed 2,144 kb
    The file sizes were for half size
    jpg 304 kb
    pdf 660 kb
    jpg compressed 304 kb
    pdf compressed 660 kb
    This was not what I was expecting since:
    For full size – although the compressed jpg was smaller than the uncompressed version, the compressed pdf was nearly twice as large as the uncompressed version
    For half size –there was no change between the compressed and uncompressed version.
    Does it make sense that the compressed pdf is larger than the original and why does compression seem to have effect after scale had been used on the original image?