On Tue, May 15, 2001 at 11:37:33PM -0700, Jacob Meuser wrote:
> On Tue, May 15, 2001 at 03:27:02PM -0700, Cory Petkovsek wrote:
> > 
> > No bob, it's not only the image size I want.  I have a bunch of images improperly 
>sized, and I need to know which one.  Next phase is to fix them.  Then I'll be 
>renaming a bunch of them (not using gimp, just perl), and I'll be resizing a whole 
>lot of them.  I'm working on about 48,000+ images!  Yikes!
> > 
> > > Image::Size is available from CPAN or in the libimage-size-perl package.
> > >
> 
> Imager can do lots of kewl things ...
> 
>  
> #! /usr/bin/perl -w
> 

Well I got bored and actually ran that through the debugger ...

Much cleaner now :)

<[EMAIL PROTECTED]>

#!/usr/bin/perl -w

use Imager;
use File::Copy;
use strict;

my $old_dir = shift || '.';
my $new_dir = "/home/cory/item";

opendir (DIR, $old_dir) or die "Can't open directory $old_dir: $!\n";
my @files = grep (/[pP].+\.jpg/, readdir(DIR));
closedir (DIR);

foreach (@files) {
    my $old_file = "$old_dir/$_";
    my $new_file = "$new_dir/$_";
    my $img = Imager->new ();
    $img->open (file=>"$old_file", type=>'jpeg')
        or warn "failed: ", $img->{ERRSTR}, "\n";
    my $width = $img->getwidth ();
    my $height = $img->getheight ();
    if (($width != 1024) || ($height != 768)){  
        print "$_: $width" . "x" . "$height\n";
        my $scaled = $img->scale(xpixels=>1024, ypixels=>768, 'min');
        $scaled->write (file=>"$new_file", type=>'jpeg') 
            or warn "failed: ", $scaled->{ERRSTR}, "\n";
    } else {
        copy ($old_file, $new_file);
    }
}

exit (0);

Reply via email to