http://www.perlmonks.org?node_id=480766

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am having a few problems with the following:
use Image::Magick; @dir_names = ("images_small"); opendir(DIR,"output_gif"); foreach (readdir(DIR)) { /^(\d+).*/; $filename = $1; push @file_convert, $filename; } opendir (DIR, "output_gif") or die "$!"; foreach $dir_name (@dir_names) { foreach $file (<@file_convert>) { $filename_orig = "output_gif\/$file.gif"; print "\tOrig = $filename_orig"; $filename_new = "$dir_name\/" . $file . ".gif"; $image = Image::Magick->new; open (IMAGE, "$filename_orig") or die "$!"; $image->Read(file=>\*IMAGE); close (IMAGE); $image->Resize(geometry=>"12.5%"); $image->Trim; $image->Set(page=> '+0,+0'); open (IMAGE2, ">$filename_new") or die "$!"; $image->Write(file=>\*IMAGE2, filename=>$filename_new); close (IMAGE2); } }
the correct filenames are being written to the new directry images_small but the files are empty?

Replies are listed 'Best First'.
Re: resize gif using ImageMagick
by zentara (Archbishop) on Aug 04, 2005 at 12:02 UTC
    Try:
    #$image->Write(file=>\*IMAGE2, filename=>$filename_new); $image->Write($filename_new);

    I'm not really a human, but I play one on earth. flash japh
      thanks for that, seems to have done the job
Re: resize gif using ImageMagick
by Jaap (Curate) on Aug 04, 2005 at 11:50 UTC
    You should either open & close the file and pass ImageMagick the filehandle, or you give ImageMagick only the filename. From the Docs:
    $x = $image->Write('x.png'); warn "$x" if "$x";
      sorry not sure if i understand correctly?