(Version: ImageMagick 6.2.9 09/24/07)

I'm scanning a directory of .pic files (school student photos), converting them to .jpg files and creating reduced thumbnail images. Initially I was executing 'convert' to do the image work, but I though Image::Magick might be a more elegant solution. So I re-wrote my code to use Image::Magick but I've hit a wall with file handle limits. It appears that Image::Magick is creating temporary file handles and not releasing them. Eventually, the file handle pool runs out and the script dies.

To illustrate I've reduced my code to a simple example the reads/converts/writes the same image file over and over again. (you'll have to provide your own images to test). When I run this example it fails at 1016:
Image Magick(1016) Read failed: Exception 430: unable to create tempor +ary file `/home/user/tmp/magick-XX376BF8': Too many open files
Is this an Image::Magick bug? Can I force Image::Magick to use ram instead of creating tmp file handles? What if anything can I do to get this example to stop failing?

example follows:
use strict; use warnings; use Image::Magick; my $image_count = 0; # provide your own test paths for these! my $src_dir = '/some/source/directory/containing/a/.pic/file'; my $dest_dir = '/some/temp/directory'; my $file = 'somepicfilename'; while (1) { convert("$src_dir/$file.pic", $dest_dir, "$file.jpg"); } sub convert { my ($src, $dest, $filename) = @_; my $image = Image::Magick->new; $image_count++; my $x = $image->Read($src); die "Image Magick($image_count) Read failed: $x\n" if $x; $x = $image->Set(quality=>'85') and die "Image Magick($image_count) Set1 failed: $x\n"; $x = $image->Write("$dest/$filename") and die "Image Magick($image_count) Write1 failed: $x\n"; #172x228 $x = $image->Crop(geometry=>'120x159+26+15') and die "Image Magick($image_count) Crop1 failed: $x\n"; $x = $image->Thumbnail(width=>86, height=>114) and die "Image Magick($image_count) Thumbnail1 failed: $x\n"; $x = $image->Set(quality=>'75') and die "Image Magick($image_count) Set2 failed: $x\n"; $x = $image->Write("$dest/thumb.$filename") and die "Image Magick($image_count) Write2 failed: $x\n"; $x = $image->Crop(geometry=>'75x90+27+25') and die "Image Magick($image_count) Crop2 failed: $x\n"; $x = $image->Thumbnail(width=>29, height=>38) and die "Image Magick($image_count) Thumbnail2 failed: $x\n"; $x = $image->Write("$dest/stamp.$filename") and die "Image Magick($image_count) Write3 failed: $x\n"; }

In reply to Image::Magick Exception 430 by ruzam

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.