Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Help with Gimp-perl

by keymon (Beadle)
on Sep 03, 2003 at 01:13 UTC ( #288476=perlquestion: print w/ replies, xml ) Need Help??
keymon has asked for the wisdom of the Perl Monks concerning the following question:

I'd like to add a "fuzzy border" to a bunch of images that are in JPEG format. The "script_fu_fuzzy_border" function in Gimp does what I want; but I'd like to script it. Here's the gist of what I have:
my $img = eval { Gimp->file_jpeg_load($file, $file) }; my $drawable = $img->active_drawable; $img->script_fu_fuzzy_border($drawable, [255, 255, 255], "16", 1, +"4", 1, "100", 0, 1); eval { Gimp->file_jpeg_save($img, $drawable, $file, $file, 0.8, 0, 1, 1, "w/ border", 0, 1, 0, 2); };
The result is the same as the original image, no change. What am I doing wrong?

Comment on Help with Gimp-perl
Download Code
Re: Help with Gimp-perl
by halley (Prior) on Sep 03, 2003 at 14:38 UTC
    I've not done any gimp-perl, but I've used GIMP quite a bit. The only thing that comes to mind is that you may need to flatten the whole $img before saving. If the script provides new layers and masks, and you're asking to save it (in the GUI), you'd be told that you must export and flatten it to a single layer entity before saving to JPEG format. Perhaps in the script, you're just saving the back layer of the results, which would be the original image without the effect of the extra layers and masks.

    [ e d @ h a l l e y . c c ]

      I just checked: I do call
      before saving. The line got missed in the cut-n-paste above.
Re: Help with Gimp-perl
by mattr (Curate) on Sep 04, 2003 at 07:23 UTC
    I looked hard but the work I did in perl-fu a year or two ago is on an archival cd somewhere in the closet.. sorry.

    But I had no problem doing masking and stuff I remember. I made a little shell with readline that would let me type a series of perl-fu commands and once I was sure it worked, I would dump it into my script. This was the only way I found to debug the stuff.

    My memory is as fuzzy as your border but.. Why not try and show the window and see what's happening? My system when run would show hundreds of windows popping open and closed, it was great. At least this will help you see if maybe the slash in your filename is tripping you up.. (does the modification date change?)

    Similarly you could make a new window, copy the image into it and be sure it is displayed so you know it is opening up correctly. Baby steps..

    By the way the shell was based on pgshell, you can search for it or just roll your own, it is only a handful of lines. I'd capture a bunch of lines and then after typing an end (maybe a period by itself) it would execute them all.

Re: Help with Gimp-perl
by IlyaM (Parson) on Sep 04, 2003 at 07:42 UTC

    Could it be that Gimp->file_jpeg_save fails? Have you tried to add check if there was raised an exception. I.e.

    eval { Gimp->file_jpeg_save(...); }; if($@) { warn $@; }

    Ilya Martynov,
    CTO IPonWEB (UK) Ltd
    Quality Perl Programming and Unix Support UK managed @ offshore prices -
    Personal website -

      The file is being saved (I checked the comments). I changed the output filename, and it gets created.

      In response to mattr's suggestion , how do I pop up windows when the entire call to script_fu_fuzzy_border() is in non-interactive mode? Maybe I'll try popping up a window of the result to see what happens.

        Have you tried to turn on debug trace (see section "DEBUGGING AIDS" in perldoc Gimp)? It may show the cause of the problem.

        Ilya Martynov,
        CTO IPonWEB (UK) Ltd
        Quality Perl Programming and Unix Support UK managed @ offshore prices -
        Personal website -

Re: Help with Gimp-perl
by Roger (Parson) on Sep 04, 2003 at 23:25 UTC
    You can turn on interactive mode by using the long version of the script_fu_fuzzy_border:

    script_fu_fuzzy_border(run_mode, image, drawable,
        color, value, toggle, value,
        toggle, value, toggle, toggle);

    Where the run_mode is INT32, Interactive/non-interactive.
    And image is the image itself.

    I believe the long version would work.
      Here's a trace of the calls to the script-fu routines, by setting Gimp's TRACE_ALL :
      #my $img = eval { Gimp->file_jpeg_load($file, $file) }; file_jpeg_load( INT32 run_mode=1 "Interactive, non-interactive" STRING filename="test.jpg" "The name of the file to load" STRING raw_filename="test.jpg" "The name of the file to load" ) = ( IMAGE image=0 "Output image" ) #my $drawable = $img->active_drawable; gimp_image_active_drawable( IMAGE image=0 "The image" ) = ( DRAWABLE drawable=2 "The active drawable" ) #$img->script_fu_fuzzy_border($drawable, [255, 255, 255], "16", 8, "4" +, 1, "100", 0, 1); script_fu_fuzzy_border( INT32 run_mode=1 "Interactive, non-interactive" IMAGE image=0 "The Image" DRAWABLE drawable=2 "The Layer" COLOR color=[255,255,255] "Color" STRING value="16" "Border Size" INT32 toggle=8 "Blur Border" STRING value="4" "Granularity (1 is Low)" INT32 toggle=1 "Add Shadow" STRING value="100" "Shadow Weight (%)" INT32 toggle=0 "Work on Copy" INT32 toggle=1 "Flatten Image" ) = ( ) file_jpeg_save( INT32 run_mode=1 "Interactive, non-interactive" IMAGE image=0 "Input image" DRAWABLE drawable=2 "Drawable to save" STRING filename="out.jpeg" "The name of the file to save +the image in" STRING raw_filename="out.jpeg" "The name of the file to save +the image in" FLOAT quality=0.800000 "Quality of saved image (0 <= quality +<= 1)" FLOAT smoothing=0.000000 "Smoothing factor for saved im +age (0 <= smoothing <= 1)" INT32 optimize=1 "Optimization of entropy encoding para +meters (0/1)" INT32 progressive=1 "Enable progressive jpeg image loading + - ignored if not compiled with HAVE_PROGRESSIVE_JPEG (0/1)" STRING comment="Kilroy was here" "Image comment" INT32 subsmp=0 "The subsampling option number" INT32 baseline=1 "Force creation of a baseline JPEG (no +n-baseline JPEGs can't be read by all decoders) (0/1)" INT32 restart=0 "Frequency of restart markers (in rows, 0 = no + restart markers)" INT32 dct=2 "DCT algorithm to use (speed/quality tradeoff) +" ) = ( )
      The relevant Perl lines are inserted above the Gimp trace. I took out the call to flatten-image, since it was already being requested as a parameter to fuzzyborder (and an explicit call didn't change the results either).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://288476]
Approved by davido
Front-paged by broquaint
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2014-07-13 00:43 GMT
Find Nodes?
    Voting Booth?

    When choosing user names for websites, I prefer to use:

    Results (243 votes), past polls