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!

In reply to GIMP Perl - PNG resolution by ncw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.