It is currently 17 Dec 2017, 17:06

GIMP Python Fu ScriptsRun Code on Visible Layers Script for GIMP (Showcase | Slideshow)

Share your Python Fu scripts for GIMP here
Post Reply
User avatar
tim

Administrator
View: Showcase | Slideshow
Topic Posts: 3/6
Posts: 2000
Joined: 25 Sep 2016, 17:16
Cash on hand: 6,288.73 GLP
Bank: 41,331.25 GLP
Gender: Guy
Location: Victoria, BC
Website: https://gimplearn.net
Operating System: Windows
GIMP Version: 2.8.22
My Personal Blog
My FineArtAmerica
x 1005
x 217
Contact:
Canada

Run Code on Visible Layers Script for GIMP

Post#1 by tim » 19 Oct 2017, 13:05


Since there isn't a way to allow users to choose a filter/plug-in/script to run on visible layers (other than having to write a custom script that does it for a specific filter), I thought I'd make a script (for fun or usefulness it's really up to you) that allows you to run your one-liner of python code (which could/should be your desired filter/plug-in/script).

:download:
run_code_on_visible_layers.zip #
zipped .py file (unzip, put in your GIMP's /plug-ins/ folder)
(1.26 KiB) Downloaded 17 times
:download:
run_code_on_visible_layers (2).zip #
version 2. Set Active Layer as well so that gmic filter can work on active layer as well.
(1.31 KiB) Downloaded 4 times
Script Menu Location: Python-Fu/Run Code on Visible Layers...

Script Options:
Run_Code_on_Visible_Layers_Script_Option.png
Run_Code_on_Visible_Layers_Script_Option.png # (24.79 KiB) Viewed 243 times (Watermarked | Thumbnail)
Instructions:
1. Turn visibility on for layers that you'd like to run the code on.
2. Determine what code you need to run. In a text editor, type out your code (python) (refer to Help > Procedure Browser).
a) Choose a function that probably starts with "python-fu" or "script-fu". Change all the hyphens (-) in the function name to underscores (_).
b) Add "pdb." in front of your function name.
c) Add parameters after your function. It probably needs an image and a layer as parameters before other parameters, so use "image" and "layer".
d) for example: pdb.script_fu_drop_shadow(image,layer,4,4,15,(0,0,0),60,False)
3. Run script (Python-fu/Run Code on Visible Layers...). Paste your line of code edited from step 2 into the "Code to Run:" option. Click "OK".
4. The Script will try to loop through all your visible layers pointing "layer" to the looped layers, and apply your code to each layer.
5. That's it.

- Example of walk-through on how to create your one-liner code (gimp-threshold).
- Zero01's example of how he successfully created one-liner to use with script after some struggle.
0 x



aka Tin
Image gimplearn.net                                              

Registered members enjoy ads-free content
User avatar
Pat625
Script Tester
View: Showcase | Slideshow
Topic Posts: 2/6
Posts: 1924
Joined: 27 Sep 2016, 20:35
Cash on hand: 11,251.12 GLP
Gender: Gal
Location: USA
Operating System: Windows
GIMP Version: 2.8.22
x 7
x 410
United States of America

Post#2 by Pat625 » 19 Oct 2017, 19:56


That is really nice, Tin. I wish I understood some code so that I could use it!
0 x




User avatar
Issabella
Script Tester
View: Showcase | Slideshow
Topic Posts: 1/6
Posts: 1639
Joined: 19 Jan 2017, 03:42
Cash on hand: 12,360.20 GLP
Gender: Gal
Operating System: Windows
x 165
x 426
Spain

Post#3 by Issabella » 20 Oct 2017, 00:37


I think like Pat. I'm sure this new script will be helpful to who knows how to use it. :thumbsup:
0 x



Issabella

User avatar
Pat625
Script Tester
View: Showcase | Slideshow
Topic Posts: 2/6
Posts: 1924
Joined: 27 Sep 2016, 20:35
Cash on hand: 11,251.12 GLP
Gender: Gal
Location: USA
Operating System: Windows
GIMP Version: 2.8.22
x 7
x 410
United States of America

Post#4 by Pat625 » 20 Oct 2017, 06:44


I would need a list of codes already written!
0 x




User avatar
tim

Administrator
View: Showcase | Slideshow
Topic Posts: 3/6
Posts: 2000
Joined: 25 Sep 2016, 17:16
Cash on hand: 6,288.73 GLP
Bank: 41,331.25 GLP
Gender: Guy
Location: Victoria, BC
Website: https://gimplearn.net
Operating System: Windows
GIMP Version: 2.8.22
My Personal Blog
My FineArtAmerica
x 1005
x 217
Contact:
Canada

Post#5 by tim » 20 Oct 2017, 07:46


Well if you need a function/filter/script that runs on visible layers, now instead of having to write a custom script ... I can provide you with a one-liner to paste in to use with this script.
So instead of 20 scripts, you'll just have 20 one-liners that you can just look up and choose which to use.
Just let me know what you want and I can quickly provide the 1 liner.
0 x



aka Tin
Image gimplearn.net                                              

User avatar
tim

Administrator
View: Showcase | Slideshow
Topic Posts: 3/6
Posts: 2000
Joined: 25 Sep 2016, 17:16
Cash on hand: 6,288.73 GLP
Bank: 41,331.25 GLP
Gender: Guy
Location: Victoria, BC
Website: https://gimplearn.net
Operating System: Windows
GIMP Version: 2.8.22
My Personal Blog
My FineArtAmerica
x 1005
x 217
Contact:
Canada

Post#6 by tim » 20 Oct 2017, 07:54


If you're really keen you can try to come up with the one-liners yourself.
For example, you want to do threshold on all visible layers.

in GIMP (Help -> Procedure Browser), type "threshold" you'll see all procedures that has the word threshold in it.
one of which is gimp-threshold.
gimp_threshold_in_procedure_browser.png
gimp_threshold_in_procedure_browser.png # (45.91 KiB) Viewed 187 times (Watermarked | Thumbnail)
it's called gimp-threshold (so we'll replace the hyphen with underscore so it's gimp_threshold)
now add a "pdb." in front of it so that it's pdb.gimp_threshold.

from the procedure browser, we can see that it takes 3 parameters (drawable, low-threshold, high-threshold)

so we'll use "layer" as the drawable and specify our own low and high thresholds.

so now we can have something like
pdb.gimp_threshold(layer,127,255)

That's it, that's a usable one-liner.
0 x



aka Tin
Image gimplearn.net                                              

Post Reply

Last 20 Members Who Visited This Topic

User avatar Pat625 (10), User avatar tim (35), User avatar oldmangrumpy (1), User avatar Wallace (3), User avatar gnerd (5), User avatar Issabella (3), User avatar Pegleg44 (1)

  • Similar Topics
    Replies
    Views
    Last post
• Featuring Members' Works (Image Attachments Only) •
1: tim
2: tim
3: animicule
4: Steve Reid
5: oldmangrumpy
6: animicule
7: trandoductin

Who is online

Users browsing this forum: No registered users and 2 guests