Perhaps particularly slow TIFF compression method is to blame, e.g. deflate, or, for bilevel images, CCITT Group 4? Do you need compression at all, for your blobs? Here for 10 Mpx RGB image (but veeery slow machine):

use strict; use warnings; use Time::HiRes 'time'; my $fn = 'test.tif'; { print "\tTesting Magick:\n"; use Image::Magick; my $img = Image::Magick-> new; $img-> Read( $fn ); for ( qw/ None LZW Zip /) { my $t = time; $img-> Set( compression => $_ ); my $blob = $img-> ImageToBlob; printf "Compression: %s \t Size: %d \t Time: %.2f\n", $_, leng +th $blob, time - $t; } } { print "\tTesting Imager:\n"; use Imager; my $img = Imager-> new( file => $fn ); for ( qw/ none lzw zip /) { my $t = time; my $blob; $img-> write( data => \$blob, type => 'tiff', tiff_compression + => $_ ); printf "Compression: %s \t Size: %d \t Time: %.2f\n", $_, leng +th $blob, time - $t; } } __END__ Testing Magick: Compression: None Size: 30063788 Time: 0.20 Compression: LZW Size: 16156294 Time: 1.11 Compression: Zip Size: 13868590 Time: 11.86 Testing Imager: Compression: none Size: 30000294 Time: 0.32 Compression: lzw Size: 26470736 Time: 1.30 Compression: zip Size: 17199450 Time: 3.98

LZW was designed for speed. Deflate was designed to replace LZW :). ImageMagick is not speed oriented, in general. My attempt was to demonstrate this with Imager, but, sadly, as I see now it writes whole TIFF as single strip, and it's not configurable. That's why its LZW is not only so much larger (for this image), but slower, too.

Update. If, for any reason, you won't use LZW (older libtiff?), for Zip there's under-documented "quality" setting (rather, zlib compression level), which lowest value of 10 gives quite a boost to speed:

my $t = time; $img-> Set( compression => 'Zip' ); # default compression level printf "Size: %d \t Time: %.2f\n", length $img-> ImageToBlob, time - $ +t; $t = time; $img-> Set( compression => 'Zip', quality => 10 ); printf "Size: %d \t Time: %.2f\n", length $img-> ImageToBlob, time - $ +t; __END__ Size: 13868590 Time: 11.41 Size: 15694516 Time: 1.92

In reply to Re: Optimize runtime with Image::Magick; by vr
in thread Optimize runtime with Image::Magick; by guacamayo

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.