[ale] Mass image cropping

Mike Harrison meuon at geeklabs.com
Tue Mar 11 16:32:04 EDT 2008


On Tue, 11 Mar 2008, Jim Popovitch wrote:

> Anyone know of a good (command line ;-) )  way to crop 100 pictures to
> the same size?
>
> Something like this would be too cool:
>
>  gimp -nogui -autocrop -offset 28x30 -newsize 100x100
> -preserve-file-names *.png

"convert" in a perl script..


This one resizes.. but you can also crop, and do all kinds of things with 
it. It's part of the imagemagick packages..

------------------------------------------------------------

#!/usr/bin/perl
#system("rm -f a-*") ;
#system("rm -f s-*") ;
#system("rm -f m-*") ;
opendir(DIRHANDLE,".") ;
@filez = readdir(DIRHANDLE) ;
foreach(@filez) { if(substr($_,0,1) eq ".") { } else {
#s/\ /_/g ;
#s/\,//g ;
$filename = "$_" ;
$_ = "\L$_" ;
s/dsc/dsw/g ;
s/\ /_/g ;
s/\,//g ;
s/\&/-/g ;
$lfilename = "$_" ;
if(/jpg/) {
print "$_\n" ;
print "mv \"$filename\" $lfilename \n" ;
system "mv \"$filename\" $lfilename" ;
#sleep 1 ;
} ;
if(/.gif/) {
print "$_\n" ;
system"mv $filename $lfilename" ;
system "convert $lfilename $lfilename.jpg" ;
} ;
} ; } ;
opendir(DIRHANDLE,".") ;
@filez = readdir(DIRHANDLE) ;
foreach(@filez) { if(substr($_,0,1) eq ".") { } else {
$filename = "$_" ;
$_ = "\L$_" ;
$lfilename = "$_" ;
$thumbed = "F" ;
if(-e "s-$filename") { } else {
         if(/jpg/) {
                 if(/^m-/) { } else {
                         if(/^s-/) { } else {
                         print "$_\n" ;
                         system("convert -quality 75 -geometry 150x120 
./$filename s-$filename") ;
                         system("convert -quality 85 -geometry 640x480 
./$filename m-$filename") ;
                         system("convert -quality 85 -geometry 1280x1024 
./$filename a-$filename") ;

                 } ;     } ;
         } ; } ; } ;
} ;
system("chown www-data:www-data *") ;
system("chown www-data:www-data .") ;



More information about the Ale mailing list