Hello @all!

How can I optimize this?

The script should read .tiff's, write a text at the top and write again to STDOUT.

until ImageToBlob () takes 0.10 ms,with ImageToBlob it takes up to 3 sec.

Thanks in advance!

#!/usr/bin/perl use strict; use warnings; use Image::Magick; use Data::Dumper; use POSIX; my $def = shift || '/var/www/html/error.tif'; my $uri = $ENV{'PATH_TRANSLATED'} || $def; my $debug = 1; my $img = Image::Magick->new(); $img->Read( "tif:" . ( -e $uri ? $uri : $def ) ); my ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mti +me, $ctime, $blksize, $blocks ) = stat($uri); my $scan_date; my $date_create = POSIX::strftime( '%d-%m-%Y %H:%M:%S', localtime $cti +me ); if ( $date_create =~ m/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}) +.*/ ) { $date_create = $3 . "." . $2 . "." . $1 . " " . $4 . ":" . $5 . ": +" . $6; } $scan_date = $date_create; $img->Annotate( y => 10, text => "Scanned: " . $scan_date, font => "ArialBkI", pointsize => 36, fill => 'white', gravity => 'north', undercolor => 'black', ); my $out = $img->ImageToBlob(); print "Content-type: image/tiff\n\n" . $out if ( $debug < 1 );

In reply to 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.