# Batch process whole directories
# jigsaw filter
# config path to installed gimp-1.2
$HOME = $ENV{'HOME'};
$home="$HOME/.gimp-1.2/scripts";
$imgtype='jpg'; # format(s) for input/output image types
$postcopy='new_'; # prefix on new images
use Getopt::Long qw(:config no_ignore_case bundling);
$|=1;
#!
#!
my $version="0.2";
my $version_date="09/09/03";
#!
#!
#Get command line options
my $flag_help=0;
my $flag_version=0;
GetOptions(
'h'=>\$flag_help, 'help'=>\$flag_help,
'v'=>\$flag_version, 'version'=>\$flag_version,
);
if ($flag_help)
{
#List Options
print STDOUT "batchgimp is a perl-based, command-line script for accessing the \n".
"Gimp Extensions/Plug-ins/Load & Save-Handlers.\n".
"To use, copy $0 to the folder where a batch of images reside.\n" .
" perl $0 \n".
" where $0 is the name of the action inside GIMP that is \n".
" being batched processed.\n" .
" As an example, to add a bevel to a group of images, in folder \n".
" $HOME/myimages, type \n\n".
" cp bevel.pl $HOME/myimages \n".
" cd $HOME/myimages \n".
" perl bevel.pl \n".
" To list the resulting beveled images,\n".
" ls -l | grep new_imageroot \n\n";
exit 0;
}
if ($flag_version)
{
#Show Version
print STDOUT "Batch Gimp - gimp calls on command-line \nfor image processing directories\n";
print STDOUT "Version number $version\n";
print STDOUT "Latest revision on $version_date\n";
print STDOUT "For more information, see http://freshmeat.net/projects/batchgimp/ \n";
exit 0;
}
# development
$debug=0;
# subs
get_images();
config();
batch();
quietgimp();
cleanup();
# file list
sub get_images {
undef @images;
$images= `du -a --max-depth=1 | grep $imgtype `;
@tmp= split(/\n+/,$images);
foreach(@tmp){
chomp;
s/^\s+|\s+$//g;
s/^.*?\///g;
push(@images,$_);
print "Working image ... $_\n";
}
}
# prepare input/output file names
sub config {
my @chars = ("A".."Z","a".."z",0..9);
$randomz = join("",@chars[ map {rand@chars}(1..3) ] );
$batch = $imgtype .'-files' . $randomz . '.scm';
$script = $imgtype .'-file' . $randomz . '.scm';
$function =$imgtype.'-function';
# write header 'define'
open(GIMP,">$path/$script") || die "Can't access gimp home directory\n";
print GIMP '(define ('.$imgtype .'-files)' . "\n";
# loop images
foreach(@images){
print GIMP "($function ". ' "'.$_ .'" "'.$postcopy.$_.'")'."\n";
}
# write footer
print GIMP ')';
}
# run
sub batch {
#
# Create the processing script
# Cut and paste Scheme to insert below in DATA
#
@scheme=;
$scheme=join('',@scheme);
$scheme=~s//$function/;
print GIMP "\n\n $scheme \n\n";
}
# batch syntax to run non-interactively
sub quietgimp {
# call the gimp quietly
my $command = " gimp --no-interface --no-data --batch '(". $imgtype ."-files)' '(gimp-quit 0)' ";
if($debug eq 0){
system("$command");
}
}
# end
sub cleanup {
close GIMP;
if($debug eq 0){
system("rm -f $path/$script");
}
}
#
# cut and paste the scheme script here
# only place holder is the function name, my-function
__DATA__
(define ( source-name dest-name )
; load the image
(set! img (car (gimp-file-load 1 source-name source-name)))
; flush the undo buffer to save swap space
(gimp-image-undo-disable img)
; flatten the layers to one for jpg
(set! drawable (car (gimp-image-flatten img)))
; call the jigsaw plug-in script with parameters
(plug-in-jigsaw 1 ; non-interactive
img ; image name
drawable ; drawable
5 ; X-number of tiles
5 ; Y-number of tiles
1 ; style shape of puzzle
3 ; blend_lines number lines for shading bevels
2 ; blend_amount light power of highlights
)
; save out the jpeg with parameter settings
(file-jpeg-save
1 ; non-interactive
img ; the input image
drawable ; flattened layer drawable to save
dest-name ; the output
dest-name ; the raw output
0.75 ; quality (0<=quality<=1)
0.00 ; smoothing (0<=smoothing factor<=1)
0 ; optimize (0,1)
0 ; progressive
"comment" ; image comment
0 ; subsampling option
1 ; baseline
0 ; restart markers
1 ; DCT algorithm
)
; clean up to redo next image
(gimp-image-undo-enable img)
)