Mario Bittencourt wrote:

> Hi,
>     I am a Photoshop user (nobody's perfect) and I've been playing with
> Gimp for a while.  Since photoshop can not do what I want (at least do
> not know how) I've decided to try to do the same thing under gimp.
>     I need to apply a set of effects (such as resize, ajust levels,
> shapen etc) to a large group of files, saving them in another directory.
>     I've developed an action under photoshop but it forces me to open
> the files manually and presse the " Go"  button for each one.
>     What I'd like to do is use Gimp (or other tool - in this case email
> me privately) to open all files located in a cretain directory, apply a
> predefined set of effects  and save the files with the same name in a
> different directory.
>     Since I've never worked with script-fu (I suppose I'll have to use
> that) I'd like to know if someone could send me some tips about this or
> even snippets of code to do what I want.


 I don't know what platform you are working on but I recently managed to
get some batch processing done in Linux using perl and the gimp-perl
module.  In fact I have been lurking this list for a week or so as I was
trying to get this working.

Here is an overview of what I did to get this working and if anyone has any
comments like "Dummy, you did not have to go through all that you could
have done blah blah I would certainly be grateful.

First, A little background.  I have a rudimentary knowledge of perl and
have been fairly involved in linux adminstration for several years. I have
an extremely basic working knowledge of gimp and almost no other graphic

The task that I ws trying to automate was the opening of a an animated gif
that is sent to us from a business partner and that is huge, 3.5 MB or so,
and sometimes comes with the layers compositing and sometimes replacing.  I
need them to be replaced.  I found, as I was trying to learn about this
image and  why it was compositing rather than replacing that if I saved it
in gimp with the correct layer defaults, that the file size was reduced to
less than 200K.

This was perfect if only I could figure out a way to automate the gimp

I wanted all software installations to be accomplished via rpm to
facilitate the recreation of the environment on other machines.  The
process is running in cron as a normal user

There are several issues I had to overcome:

  1. 1. upgrading gimp to the latest I could find in order to justifiably
     ask for help.  The server and my test box are both running redhat 6.2
     with several, but as I found not all, the upgrades availible from
     redhat.  I found an rpm that worked perfectly at
  2. 2. upgrading perl with the modules that would provide the hooks into
  3. 3. running on a machine with no X (gui interface ) running
  4. 4. Figuring out what the syntax was in perl to call gimp
  5. 5. trouble shooting errors

The packages that I installed were as follows:
perl-Gtk-Perl 0.7000 6     from
Mesa 3.2 2                     redhat cd
perl-PDL 2.003 6
gtk+ 1.2.8 1
gimp 1.2.0 1            
gimp-perl 1.2.0 1    
XFree86-Xvfb 3.3.6 20         redhat cd

Ther perl modules alread installed were:
perl 5.00503 2
perl-libnet 1.0605 2
perl-Tk 800.018 1
perl-HTML-Parser 3.05 6
perl-libwww-perl 5.47 6
perl-URI 1.05 6
perl-Net-SSLeay 1.05 5

I had to upgrade glib package to install the new gtk+ on one of the boxes

I then had to make sure there was an X display that gimp could use,
otherwise the script would hang and gimp showed up in a ps axf output as

This was not a problem until I moved to the X-less server.  On the server I
started Xvfb with the following line in a script startXvfb:

scripts]$ cat startXvfb
Xvfb :1 -screen 0 10x10x8 -pixdepths 1 -fp

I leave this running on the server started as the user the cron process
runs as with the following command line:

nohup startXvfb &

The perl program that does my conversion is called

scripts]$ cat
#!/usr/bin/perl  -w
print "entering $0\n";
use File::Basename;
$numargs = @ARGV;
$progname= basename($0);

if  ( $numargs != 2 ){
print " the number of args is $numargs\n";
print "Incorrect number of arguments. \nUsage $progname infile outfile\n";
exit 1;
use Gimp;
use Gimp::Fu;
#set_trace is important to see what gimp is doing.
#You don't get this in script-fu as far as I could learn
print `date '+%b %d %T' `."loading $ARGV[0]\n";
my $img = Gimp->file_gif_load("$ARGV[0]","$ARGV[0]");
print "return code = $?\n";
print `date '+%b %d %T' `."Converting to indexed\n";
$img->convert_indexed (0,0,255,0,1,"");
print "return code = $?\n";
print `date '+%b %d %T' `."Saving as $ARGV[1]\n";
$img->file_gif_save (0,"$ARGV[1]","$ARGV[1]",0,1,500,2);
print "return code = $?\n";

The important parts of the script called from cron is as follows

scripts]$ cat updatewdt
#set the DISPLAY varibale to the one that the Xvfb process is on
# Comment this out if you are going to be running from an xterm
#and don't need the virual framebuffer provided by the Xvfb package
export DISPLAY=:1
cd $downloaddir
echo $(date '+%b %d %T') "beginning `basename $0`"
echo "calling to use gimp to convert file "
if ! ($scriptdir/ radar.gif radarbatch.gif) then
 echo "there was a problem with"
 exit 1

In gimp 1.2 the PDB Browser was a great help in finding the correct
arguments to pass to the perl functions.

This was a very involved process finding all these pieces and getting them
to play nice together.  (I spent the better part of a week)  I now have a
rough outline that as I dream up stuff in the future to do, I think I will
be able to get there much quicker.

I just finished this and still have some error checking to add and maybe
some playing with the perlserver that is supposed to alieviate the need of
starting gimp each time but for now it works.  I have considered creating a
how to but time is tight and I don't really know how helpful this
information is or how many folks need to do this but since your post popped
up and I need to document this for my self anyway here ya go.  I hope this

If you decide to give this a try, let me know if there is anything you have
problems with at least as far as the initial config goes, and I would be
happy to try to help.


Gimp-user mailing list

Reply via email to