Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

resize gif using ImageMagick

by Anonymous Monk
on Aug 04, 2005 at 11:14 UTC ( #480766=perlquestion: print w/replies, xml ) Need Help??

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
    #$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?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://480766]
Approved by Nevtlathiel
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2021-10-16 10:09 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (69 votes). Check out past polls.