Advertisement
Guest User

image_resizer_by_ratio

a guest
Nov 19th, 2010
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.83 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 $ratio       = 1/3;
  6.  
  7. my $image       = Image::Magick->new;    # create object
  8. foreach (@ARGV) {
  9.   opendir(DIR, $_) or die "Can't opendir $_: $!";
  10.   while (defined(my $file = readdir(DIR))) {
  11.     if ($file =~ m/.jpg$/i){        # skip if not a JPEG file
  12.       my $path   = "$_/$file";
  13.  
  14.       ## Image processing
  15.       $image    -> Read($path);
  16.       my $width  = $image->Get('columns');
  17.       my $height = $image->Get('height');
  18.       $image    -> Resize(width  => ($width  * $ratio),
  19.                           height => ($height * $ratio),
  20.                           );
  21.       $image    -> Write(filename    => $path);
  22.       undef @$image;                # delete image
  23.     }
  24.   }
  25.   closedir(DIR);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement