I am using Imager on a Windows test computer. It is processing about 60 files. I realise image processing is CPU intensive ... but the browser times out before the process has run - about 60 seconds. For PERL, that seems incredibly slow, so I must be doing something wrong

The files are approx 3508px x 2480px -jpg. I am reducing down to 750 wide, and another 150px tall. The third is being rotated 90 degrees anti-clockwise. (I found out it cannot handle type=>jpg,so changed that to "type='jpeg'" wcev though the extension is '.jpg')

I placed the new image outside of the loop thinking that once created, it would use the same variable. Here then is the code:

$dir=$baseURL.$type."/"; # Reads the photos in master folder. Calle +d 3 times via external loop opendir my $dh, $dir or die "Could not open '$dir' for reading '$!'\n" +; @pics = grep(/\.jpg$/,readdir $dh); closedir $dh; shift @pics; ## Removes the dot files shift @pics; $tot=@pics; $img=Imager->new(); # create empty image for (my $p=0; $p<@pics; $p++){ $img->read(file=>$baseURL.$type.'/'.$pics[$p],type=>'jpeg') or di +e $img->errstr(); my $med = $img->copy(); my $thumb = $img->copy(); $med = $img->scale(xpixels=>750);# sets width to 750px $med->write(file=>$baseURL.$type.'/medium/'.$pics[$p]) or die $ima +ge->errstr; # Write out image $thumb = $img->scale(ypixels=>150);# sets the height to 150px $thumb->write(file=>$baseURL.$type.'/thumbs/'.$pics[$p]) or die $i +mage->errstr; # Write out image my $rot90 = $img->rotate(degrees=>-90); $rot90->write(file=>$baseURL.$type.'/upright/'.$pics[$p]) or die $ +image->errstr; # Write out image my @pic=split(/\./,$pics[$p]); # splits filename at dot [filename] +[jpg] $newDat.=$pic[0].'|'; # Used in a latter part of program }

Just tries a little experiment. Two files of 10630 x 2480 took 10 seconds to process. Add 16 images of 5315px x 2480px, and browser times out after 70 secs before files are processed. (If I cut out the image processing, it can read the files, split filenames and create textfiles in about 0.5sec)

I don't really want to resort to ImageMagic as I cannot get the perlMagic interface to install on Windows offline test machine. And GD produces some poor results, messing with the colours.

Is it perhaps running out of memory, and I somehow need to clear it out before processing each image. The docs don;t eplain that as it seems to mainly work on one image at a time

Oh, and as I'm writing this Dec 23rd, "MERRY CHRISTMAS, ONE AND ALL !!"


In reply to Imager: Gateway Timeout by cristofayre

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.