I have a bunch of scanned images that people are accessing via a web app. The original images are monochrome TIF format and around 2200x1600 pixels. I need to convert them to a format that browsers can display and resize them to a range of smaller sizes. We have a working solution that converts the images on the fly and caches the results but it's a little slow so I'm looking for advice on alternative tools.

The current code calls the 'convert' program from the ImageMagick suite via the system function. It takes approximately 1.5 seconds to resize an image to a 1024x768 PNG. The originals are quite small (40KB) since they're 1 bit per pixel. The PNG is truecolour and closer to 300KB. So far I haven't found the magic combination of command-line arguments to the 'convert' program to make it produce an indexed color PNG. The large file sizes add network delays on top of the file conversion delay.

The first thing I tried was using the Image::Magick module rather than shelling out to the 'convert' command. As far as I can tell I'm using equivalent options, but the run time increases to 2.5 seconds per image and the resulting files are nearly 400KB. I've also been unable to get a conversion to indexed colour working with the module.

Next I tried the Imager module. It is able to produce indexed colour images and with a palette of 8 colours the file size is down to 70KB. Unfortunately the run time is up to 2.5 seconds and the images are rather blurry. Adding an 'unsharp' transform fixes the blur but adds another second of run time.

Finally, I tried the GD module. Unfortunately GD doesn't support TIF format so I read the source files in via a tifftopnm $in_file | pnmtopng pipeline. At 8 colour output the file size is down to a respectable 60KB and the image quality is fine but the run time is around 2 seconds per image.

The 'solution' is likely to involve pre-caching the resized images so that users don't see the delay. However, given that new images are coming in at a rate of thousands per day, reducing the conversion run time would still be useful. Can anyone suggest any other Perl modules or image conversion tools worth checking out?


In reply to Resizing large TIF files by grantm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.