It is currently 18 Feb 2018, 01:28

GIMP Script RequestsPath to Darken Layer Script Revision Request (Showcase | Slideshow)

Post your Script Requests for GIMP here.
Forum rules
Request your Script(s) for GIMP here in this forum.
Provide details of steps performed in GIMP so that script can be written for the process and also give the request a name so that scripts can be named after.
Post Reply
User avatar
Pegleg44

Forum Member
View: Showcase | Slideshow
Topic Posts: 2/4
Posts: 43
Joined: 29 Nov 2016, 03:12
Cash on hand: 258.13 GLP
x 11
Gimp Nation

Path to Darken Layer Script Revision Request

Post#1 by Pegleg44 » 25 Feb 2017, 22:52


Tim

I would like this script to have the functionality of not creating the new layer on the top of the layer stacking order. That's the most important function that I would want.

I also have figured out a way to shorten the steps it takes to perform the whole function. I wrote instructions in the code. It should be pretty easy for you to alter. I tried it myself but it doesn't work. I made requests in the code with --UPPER CASE LETTERS-- so you can just go right through.

If you do this one, then I will be able to disable the path to selection and rename everything to create the other script which is Selection to Darken Only layer. Most of the code stays the same. Here's the code.

Code: Select all

;script as described by PegLeg44 here: http://gimpchat.com/viewtopic.php?f=9&t=14046
;-----------------------------------------------------------------------------------


;rel 1. changed previous script to Path To Darken Layer 
;rel 2. set default colors to black and white before running script

(define (script-fu-path-to-darken-layer image layer 
         )
	
		(let* 
		   (
		   (width (car (gimp-image-width image)))
		   (height (car (gimp-image-height image)))
		   (active-vectors 0)
		   (new-layer 0)
		   )
			;(gimp-image-undo-disable image); DN = NO UNDO
			(gimp-context-push)
			(gimp-image-undo-group-start image)                   ;undo-group in one step
			
			
			;0. Set default colors to black and white before running script
			(gimp-context-set-default-colors)
			
			;1. I turn the path to a [Selection] [From Path].
			(set! active-vectors (car (gimp-image-get-active-vectors image)))
			(gimp-image-select-item image CHANNEL-OP-REPLACE active-vectors)
			
			;2. I create a new white layer.  --CHANGE TO TRANSPARENT AND NEXT LAYER UP INSTEAD OF TOP LAYER IN STACKING ORDER--
			(set! new-layer (car (gimp-layer-new image width height
	                           RGBA-IMAGE "new white" 100 NORMAL-MODE)))
			(gimp-drawable-fill new-layer WHITE-FILL)         ;fills background with white
			(gimp-image-insert-layer image new-layer 0 0) ;parent 0, insert layer on top position(0)				   
	
			;3. And fill the selection with black [Fill with Foreground Color]. --CHANGE TO WHITE--
			(gimp-edit-fill new-layer FOREGROUND-FILL)
			
			;4. And then un-select [Select] [None].
			(gimp-selection-none image)
			
			;5. Then I run the [Colors] [Threshold] on the layer (with the standard 127 and 255 setting). --CHANGE TO RUN "plug-in-threshold-alpha"
			(gimp-threshold new-layer 127 255)
			
			;6. And run [Layers] [Transparency] [Color to Alpha] on it. --DON'T NEED THIS--
			;(plug-in-colortoalpha 1 image new-layer '(255 255 255))
			
			;7. Then click the button [Lock Alpha Channel] at the top of the layers dockable dialog.
			(gimp-layer-set-lock-alpha new-layer TRUE)
			
			;8. Change the layer mode to [Darken Only]
			(gimp-layer-set-mode new-layer DARKEN-ONLY-MODE)
			
			;9. And finally use [Colors] [Invert] on it to make the black white. --DON'T NEED THIS--
			;(gimp-invert new-layer)
			
			;10. 10 run the [Layer] [Transparency] [Alpha to Selection] and then 
			(gimp-image-select-item image CHANNEL-OP-REPLACE new-layer)
			
			;step 11 [Layer] [Crop to Selection] 
            (plug-in-autocrop-layer 1 image new-layer)
			
		   ;(gimp-image-undo-enable image) ;DN = NO UNDO
			(gimp-image-undo-group-end image)                     ;undo group in one step
			(gimp-context-pop)
			(gimp-displays-flush)
	    )
	
	
    
) ;end of define
(script-fu-register
  "script-fu-path-to-darken-layer"         ;function name
  "<Image>/GIMP CAD/Path To Darken Layer"    ;menu register
  "Builds a New Layer with a Sharp Transparency From a Path"       ;description
  "Tin Tran"                          ;author name
  "copyright info and description"         ;copyright info or description
  "2016"                          ;date
  "RGB*, GRAY*"                        ;mode
  SF-IMAGE      "Image" 0                   
  SF-DRAWABLE   "Layer" 0
  ;SF-STRING     "Text" "Gimp Chat"
)
Thanks, Alan
0 x




Registered members enjoy ads-free content
User avatar
tim
Administrator
View: Showcase | Slideshow
Topic Posts: 2/4
Posts: 2155
Joined: 26 Sep 2016, 00:16
Cash on hand: 7,887.02 GLP
Bank: 51,356.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 1192
x 256
Contact:
Canada

Post#2 by tim » 26 Feb 2017, 00:06


give this a try and let me know.

Code: Select all

;script as described by PegLeg44 here: http://gimpchat.com/viewtopic.php?f=9&t=14046
;-----------------------------------------------------------------------------------


;rel 1. changed previous script to Path To Darken Layer 
;rel 2. set default colors to black and white before running script
;rel 3. changed according to comments and put layer above selected layer instead of top of stack.
(define (script-fu-path-to-darken-layer image layer 
         )
	
		(let* 
		   (
		   (width (car (gimp-image-width image)))
		   (height (car (gimp-image-height image)))
		   (active-vectors 0)
		   (new-layer 0)
		   (layer-position 0)
		   )
			;(gimp-image-undo-disable image); DN = NO UNDO
			(gimp-context-push)
			(gimp-image-undo-group-start image)                   ;undo-group in one step
			
			
			;0. Set default colors to black and white before running script
			(gimp-context-set-default-colors)
			
			;1. I turn the path to a [Selection] [From Path].
			(set! active-vectors (car (gimp-image-get-active-vectors image)))
			(gimp-image-select-item image CHANNEL-OP-REPLACE active-vectors)
			
			;2. I create a new white layer.  --CHANGE TO TRANSPARENT AND NEXT LAYER UP INSTEAD OF TOP LAYER IN STACKING ORDER--
			(set! new-layer (car (gimp-layer-new image width height
	                           RGBA-IMAGE "new transparent" 100 NORMAL-MODE)))
			;(gimp-drawable-fill new-layer WHITE-FILL)         ;fills background with white
			(set! layer-position (car (gimp-image-get-item-position image layer)))
			(gimp-image-insert-layer image new-layer 0 layer-position) ;parent 0, insert layer on top position(0)				   
	
			;3. And fill the selection with black [Fill with Foreground Color]. --CHANGE TO WHITE--
			(gimp-edit-fill new-layer WHITE-FILL)
			
			;4. And then un-select [Select] [None].
			(gimp-selection-none image)
			
			;5. Then I run the [Colors] [Threshold] on the layer (with the standard 127 and 255 setting). --CHANGE TO RUN "plug-in-threshold-alpha"
			;(gimp-threshold new-layer 127 255)
			(plug-in-threshold-alpha 1 image new-layer 127)
			
			;6. And run [Layers] [Transparency] [Color to Alpha] on it. --DON'T NEED THIS--
			;(plug-in-colortoalpha 1 image new-layer '(255 255 255))
			
			;7. Then click the button [Lock Alpha Channel] at the top of the layers dockable dialog.
			(gimp-layer-set-lock-alpha new-layer TRUE)
			
			;8. Change the layer mode to [Darken Only]
			(gimp-layer-set-mode new-layer DARKEN-ONLY-MODE)
			
			;9. And finally use [Colors] [Invert] on it to make the black white. --DON'T NEED THIS--
			;(gimp-invert new-layer)
			
			;10. 10 run the [Layer] [Transparency] [Alpha to Selection] and then 
			(gimp-image-select-item image CHANNEL-OP-REPLACE new-layer)
			
			;step 11 [Layer] [Crop to Selection] 
            (plug-in-autocrop-layer 1 image new-layer)
			
		   ;(gimp-image-undo-enable image) ;DN = NO UNDO
			(gimp-image-undo-group-end image)                     ;undo group in one step
			(gimp-context-pop)
			(gimp-displays-flush)
	    )
	
	
    
) ;end of define
(script-fu-register
  "script-fu-path-to-darken-layer"         ;function name
  "<Image>/GIMP CAD/Path To Darken Layer"    ;menu register
  "Builds a New Layer with a Sharp Transparency From a Path"       ;description
  "Tin Tran"                          ;author name
  "copyright info and description"         ;copyright info or description
  "2016"                          ;date
  "RGB*, GRAY*"                        ;mode
  SF-IMAGE      "Image" 0                   
  SF-DRAWABLE   "Layer" 0
  ;SF-STRING     "Text" "Gimp Chat"
)
0 x



aka Tin
Image gimplearn.net                                              

User avatar
Pegleg44

Forum Member
View: Showcase | Slideshow
Topic Posts: 2/4
Posts: 43
Joined: 29 Nov 2016, 03:12
Cash on hand: 258.13 GLP
x 11
Gimp Nation

Post#3 by Pegleg44 » 26 Feb 2017, 02:59


Got it and it works fantastically. Thanks Much!

I also changed the names to create another version of it that works directly from a selection instead of a path.
If I ever wanted to use the code to make another version that creates a normal layer mode then what would I replace the "DARKEN-ONLY-MODE" with?

Alan
0 x




User avatar
tim
Administrator
View: Showcase | Slideshow
Topic Posts: 2/4
Posts: 2155
Joined: 26 Sep 2016, 00:16
Cash on hand: 7,887.02 GLP
Bank: 51,356.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 1192
x 256
Contact:
Canada

Post#4 by tim » 26 Feb 2017, 04:55


If you want to make another version you'll have to change the

Code: Select all

(define (script-fu-path-to-darken-layer image layer 
to something like

Code: Select all

(define (script-fu-your-new-whatever-name image layer
then change

Code: Select all

(script-fu-register
  "script-fu-path-to-darken-layer"         ;function name
to something like

Code: Select all

(script-fu-register
 "script-fu-your-new-whatever-name"    ;function name
also don't forget to change the menu register line

Code: Select all

"<Image>/GIMP CAD/Path To Darken Layer"    ;menu register
and you can replace DARKEN-ONLY-MODE
to NORMAL-MODE
if you want to see list of all the modes ... in GIMP, go to Help>Procedure browser
then type in set-mode to search for functions that are named like that
and you will see gimp-layer-set-mode show up
and on the right hand side you'll all the possible modes to use. you can write in code in CAPS like NORMAL-MODE or write 0 as it is in the bracket for NORMAL-MODE(0) meaning you can use the constant name NORMAL-MODE or use the integer value of NORMAL-MODE which is 0.
0 x



aka Tin
Image gimplearn.net                                              

Post Reply

Last 20 Members Who Visited This Topic

akaawol (1), User avatar gnerd (1)

  • Similar Topics
    Replies
    Views
    Last post
• Featuring Members' Works (Image Attachments Only) •
1: gnerd
2: Issabella
3: tim
4: tim
5: dinasset
6: tim
7: tim

Who is online

Users browsing this forum: No registered users and 1 guest