I've been wanting to play with the Gimp::Fu modules and
recently a perfect example came to me. I had a pile of PNG files
which I needed to set the resolution (the dots per inch) of. I searched high and low for a program
to do this but I couldn't find one. I could have written one in C using the PNG library
but that seemed to be the only option (I couldn't find
any useful Perl modules to help).
However I noticed the GIMP could set the resolution of PNGs
so I wrote the following script. You can put it in your plugins directory and use it as part of the GIMP or you can use it as a command line program. You'll want to run the GIMP and start the Perl Server on Xtns=>Perl=>Server. Call it as :-
set-image-dpi.pl -dpi dpi -input /path/to/input_file -o /path/to/output_file.
I thought I share this with you since I haven't seen any GIMP Perl scripts on PerlMonks and a simple example like this might get the ball rolling!
#!/usr/bin/perl -w
use strict;
use Gimp ":auto";
use Gimp::Fu;
sub set_image_dpi
{
my ($dpi, $input) = @_;
# Load the file
my $img = gimp_file_load($input, $input);
# Set the resolution
$img->set_resolution($dpi, $dpi);
# Return the image
return $img;
}
register
"set_image_dpi", # name
"Set Image DPI", # small description
"Sets the dots per inch of an image", # help text
"Nick Craig-Wood", # Author name
"Nick Craig-Wood", # Copyright
"2001-08-01", # Date
"<Toolbox>/Xtns/Perl-Fu/Set Image DPI", # menu path
"*", # Image types
[
[PF_FLOAT, "dpi", "New DPI of image", 72],
[PF_FILE, "input", "Input File Name", ""],
],
\&set_image_dpi;
exit main();
Quite simple eh. Gimp coding is fun!