Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

GIMP Perl - PNG resolution

by ncw (Friar)
on Aug 12, 2001 at 21:57 UTC ( #104272=CUFP: print w/replies, xml ) Need Help??

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!

Replies are listed 'Best First'.
Re: GIMP Perl - PNG resolution
by abstracts (Hermit) on Aug 12, 2001 at 22:37 UTC
    Hello

    Sorry to spoil the fun but you can use ImageMagick's mogrify command to do:bash$ mogrify -units PixelsPerInch -density '300x300' *.png

    Hope this helps next time :-)

    Aziz,,,

    PS. You can also use Image::Magick from perl to do the same. I guess you can also use bulldozer to take out a nail :-)

      Yeah, it's a nice piece of code, new but when you can use the simple command line option, you might as well be lazy and use it instead. :)

      I am currently learning about image manipulation using Perl and through Image::Magick, so that is much fun! If you have any questions about it, please /msg me! I can try to help ya any way I can.

      Andy Summers
Re: GIMP Perl - PNG resolution
by John M. Dlugosz (Monsignor) on Aug 13, 2001 at 08:51 UTC
    Although I agree that this is overkill for the specific problem, I'm fascenated by how you programmed a new command for Gimp in Perl.

    I looked at Gimp once, and the docs for "Script fu" basically said "this is for scripting" and was horribly inadiquite.

    But, I thought it was an internal language, like what emacs does. How does it call functions in a perl script?

    —John

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://104272]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2022-01-19 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (55 votes). Check out past polls.

    Notices?