Advertisement
Guest User

image_resizer_size

a guest
Nov 19th, 2010
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.75 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. use strict;         # Enforce some good programming rules
  3. use Image::Magick;  # Module for image processing
  4.  
  5. my $width       = 800;
  6. my $height      = 600;
  7.  
  8. my $image       = Image::Magick->new;    # create object
  9. foreach (@ARGV) {
  10.   opendir(DIR, $_) or die "Can't opendir $_: $!";
  11.   while (defined(my $file = readdir(DIR))) {
  12.     if ($file =~ m/.jpg$/i){        # skip if not a JPEG file
  13.       my $path   = "$_/$file";
  14.  
  15.       ## Image processing
  16.       $image    -> Read($path);
  17.       $image    -> Resize(width   => $width,
  18.                           height  => $height,
  19.                           );
  20.       $image    -> Write(filename => $path);
  21.       undef @$image;                # delete image
  22.     }
  23.   }
  24.   closedir(DIR);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement