Best of the Newsgroups: Perl ImageMagick scal image sizes
What is this stuff?
Main Index
From: zentara@highstream.net
Subject: Re: program to run another program
Date: Mon, 15 Aug 2005 07:35:54 -0400
Message-ID: <4pu0g19j119j22gs1hcqe8rnnsk7bbof44@4ax.com>
References: <m2y874h292.fsf@west_f1.net>
On Sun, 14 Aug 2005 16:08:17 GMT, Mike Ballard <dont_w@nt_spam.org>
wrote:
>
>This is going to sound loopy but is there any program that can run and
>operate another program's GUI? I have a ton of jpgs from scans and have
>discovered that loading any into xv and resaving them the file sizes are
>(sometimes) reduced up to 90%. The problem is xv has no batch mode and I
>can't see manually loading/resaving every single scan. I don't know what
>xv is doing to get them so much smaller but I sure would like to be able
>to do this to every one if there's a way to automate it.
>
>Mike
Perl makes this stuff very easy. How are you trying to convert the
jpg's? Are you making thumbnails or what?
Just run this script in the directory of jpg's.
#!/usr/bin/perl
use warnings;
use strict;
use Image::Magick;
my $image = Image::Magick->new;
umask 0022;
my @pics= <*.jpg>;
foreach my $pic (@pics){
my ($picbasename) = $pic =~ /^(.*).jpg$/;
my $ok;
$ok = $image->Read($pic) and warn ($ok);
my $thumb = $picbasename . '-t.jpg';
$image->Scale(geometry => '100x100');
$ok = $image->Write($thumb) and warn ($ok);
undef @$image; #needed if $image is created outside loop
print "$pic -> $thumb\n";
}
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Add your comments