Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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
Node Status?
node history
Node Type: perlquestion [id://480766]
Approved by Nevtlathiel
[Discipulus]: if more than 3 go for named variables LA
[Lady_Aleena]: Discipulus, it is at 2 now, but with what I am thinking about, it could go to 3. However, only 1 is needed. The second and third are optional.
[shmem]: straight list or named parameters - that depends on whether (and how many) optional arguments you have
[Discipulus]: if so a plain list is ok, imho
[Lady_Aleena]: shmem, I already have the plugin installed, just not active.
[shmem]: if you have 1 optional argument, place that at the end of the list. If you have more, go for named parameters.
[Lady_Aleena]: 1 manditory, 2 optional.
[Discipulus]: my ($need,$opta,$optb ) = @_; .. if $opta..
[shmem]: all else leads to trouble, even if the third argument depends on the existence of the second. That may become brittle.
[Discipulus]: but if have case like subname(15,undef,3 ) maybe bettere named parameters

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2017-04-27 12:19 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (506 votes). Check out past polls.