It is currently 20 Feb 2018, 13:30

GIMP Script RequestsBlend2AlphaLayers - Script Idea (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/5
Posts: 43
Joined: 29 Nov 2016, 03:12
Cash on hand: 258.13 GLP
x 11
Gimp Nation

Blend2AlphaLayers - Script Idea

Post#1 by Pegleg44 » 21 Oct 2017, 01:20


Blend2AlphaLayers Script

Hi Tin

I've been working on the steps needed for a script that will create a straight black to white blend gradient between the pixels that are drawn on two seperate alpha layers.

So how it would work is that you create an alpha layer and draw whatever you want on it with a flat black pencil. And then create a second alpha layer and draw whatever you want on it in flat black. Then run the script on it to make a blend between the two sets of pixels of the two layers.


---------------------------------------------------------------
For an example heres a canvas size image area of 640 x 480 with one opaque alpha layer that has some simple lines drawn on it in flat black.

Image


---------------------------------------------------------------
And then here's the other alpha layer with other lines drawn on it in flat black.

Image


---------------------------------------------------------------
And here's what it will look like after running through the steps.

Image


---------------------------------------------------------------
This shows what the blend looks like in my 3D image viewer. It's a straight blend from black to white.

Image

Basically what the script will do is first duplicate the image so that the original is still untouched, then create a blend from the selection of each layer utilizing the gimp menu [select] [border] [feather border] funtion on each of the layers. The divide layer mode is then used to create a blend of each half of the space inbetween the pixels of both layers and a new layer is created for each half. Then the [colors] [map] [gradient map] is used to correct and straighten each half out so that they seamlessly mach up with each other into a straight blend from one to the other using the custom gradients that I have attached below.

Anything could be drawn on the layers and also any color can be used. But black would be the standard approach. Antialiased or feathered edges may not work as expected so use flat graphics or the pencil tool. You don't have to use lines. You could use shapes too. Most often it may give good results when the pixels are spaced appart evenly but it will work just as well if pixels overlap each other. The outcome of the script could be changed using [colors] [map] [gradient map] to achieve the gradient color that you want.

The script will need to call upon two gradients that I have created and attached here.

https://netorgft2540971-my.sharepoint.c ... MVBcaoXFSM

https://netorgft2540971-my.sharepoint.c ... OtGglZ8G8A

The script will also call upon another script that you (Tin) have created called: new_darken_layer_from_visible

Code: Select all

#!/usr/bin/env python

# New Darken Layer from Visible Rel 1
# suggested by Pegleg44 http://bakon.ca/gimplearn/new-darken-layer-from-visible-script-436
# Created by Tin Tran http://bakon.ca/gimplearn/
# Comments directed to http://gimplearn.com or http://gimp-forum.net or http://gimpchat.com or http://gimpscripts.com
#
# License: GPLv3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY# without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# To view a copy of the GNU General Public License
# visit: http://www.gnu.org/licenses/gpl.html
#
#
# ------------
#| Change Log |
# ------------
# Rel 1: Initial release.
import math
import string
#import Image
from gimpfu import *
from array import array
import sys
def python_new_darken_layer_from_visible(image, layer) :
	pdb.gimp_image_undo_group_start(image)
	pdb.gimp_context_push()
	
	#New Darken Layer from Visible
	#Here's the steps:
#0. [Select] [Select None]
	pdb.gimp_selection_none(image)
#1. [Layer] [New Layer from Visible]
	new_visible = pdb.gimp_layer_new_from_visible(image,image,"new from visible");
	pdb.gimp_image_insert_layer(image,new_visible,None,pdb.gimp_image_get_item_position(image,layer))
#2. [Layer] [ Transparency] [ Color to Alpha]
	pdb.plug_in_colortoalpha(image,new_visible,(255,255,255))
#3. [Tools] [ Default Colors] the next step needs a white background layer active
	pdb.gimp_context_set_default_colors()
#4. [Layer] [Transparency] [ Semi-Flatten]
	pdb.plug_in_semiflatten(image,new_visible)
#5. Set colors back to what they were before. This was done on a different script but doesn't really need to be included.
	pdb.gimp_context_pop()
	pdb.gimp_context_push()
#6. Lock the Alpha Channel (Button in the Layers Dock-able dialog.
	pdb.gimp_layer_set_lock_alpha(new_visible,True)
#7. Layer mode to [Darken Only]
	pdb.gimp_layer_set_mode(new_visible,DARKEN_ONLY_MODE)
#8. [Layer] [Transparency] [Alpha to Selection]
	pdb.gimp_image_select_item(image,CHANNEL_OP_REPLACE,new_visible)
#9. [Layer] Crop to Selection]
	pdb.plug_in_autocrop_layer(image,new_visible)
#The tool tip could be: Combines Height Layers into One Cropped Darken Only Layer

	pdb.gimp_context_pop()
	pdb.gimp_image_undo_group_end(image)
	pdb.gimp_displays_flush()
    #return

register(
	"python_fu_new_darken_layer_from_visible",                           
	"Combines Height Layers into One Cropped Darken Only Layer",
	"Combines Height Layers into One Cropped Darken Only Layer",
	"Tin Tran",
	"Tin Tran",
	"2017",
	"<Image>/HEIGHT TOOLS/New Darken Layer From Visible",             #Menu path
	"RGB*, GRAY*", 
	[
	#(PF_COLOR, "oldcolor",  "Replace Color:",  (43,198,255)),
	#(PF_COLOR, "newcolor",  "With New Color:",  (255,198,0)),
	#(PF_SPINNER, "x1", "x1:", 0, (0, 100, 0.5)),
	#(PF_SPINNER, "y1", "y1:", 100, (0, 100, 0.5)),
	#(PF_SPINNER, "x2", "x2:", 100, (0, 100, 0.5)),
	#(PF_SPINNER, "y2", "y2:", 0, (0, 100, 0.5)),
	#(PF_COLOR, "black",  "Black point color",  (0,0,0) PF_FILE, "infilename", "Temp Filepath", "/Default/Path"),
	#(PF_COLOR, "white",  "White point color",  (255,255,255) ),
	#(PF_COLOR, "gray",  "Gray point color",  (128,128,128) )
	#(PF_FILE, "infilename", "Temp Filepath", "/Default/Path")
	#(PF_DIRNAME, "source_directory", "Source Directory", "") for some reason, on my computer when i(Tin) use PF_DIRNAME the pythonw.exe would crash
	],
	[],
	python_new_darken_layer_from_visible)

main()

Maybe you (Tin) will include new code into the script to make it so it doens't depend on the original script as an external script which creates a layer with the "Darken Only" Mode. If you do, then maybe you can make it so that it creates the new layer from visible and ends up with a new layer that has a layer mode of normal on step 17 and 23 thus eliminating steps 18 and 23.

I think this script would work fast because it's all raster. A pixel setting of 256 applied to the [Select] [Border] setting is the highest that can be used because anything more will create unwanted areas of pixilation in the gradient. So the open opaque areas between the two alpha layer pixels should remain within 256 pixels to work optimally.

Here's the steps that the script will need to perform to get the outcome only after the two opaque alpha layers have been created and are the only layers in the image. In other words you start this script on an image that contains only two layers with opaque areas.

1.[Image] [Duplicate Image]
2.[Tools] [Default Colors]
3. [Layer] [Stack] [Select Bottom Layer]
4. [Layer] [Transparency] [Alpha to Selection]
5. [Select] [Border] "256 px" and "Feather Border" settings
6. [Edit] [Fill with FG Color]
7. [Select] [None]
8. [Layer] [Transparency] [Semi Flatten]
9. Change the Layer Mode to "Divide"
10. [Layer] [Stack] [Select Top Layer]
11. [Layer] [Transparency] [Alpha to Selection]
12. [Select] [Border] "256 px" and "Feather Border" settings
13. [Edit] [Fill with FG Color]
14. [Select] [None]
15. [Layer] [Transparency] [Semi Flatten]
16. Change the Layer Mode to "Divide"
17. Run the Script "new_darken_layer_from_visible
18. Change the Layer Mode of this new layer to "Normal"
19. [Colors] [Map] [Gradient Map] to run the gradient called "AlphaLayersGradientA"
20. Turn the Layer Visibility Off
21. [Layer] [Stack] [Select Bottom Layer]
22. [Layer] [Stack] [Raise Layer]
23. Run the Script "new_darken_layer_from_visible
24. Change the Layer Mode of this new layer to "Normal"
25. [Colors] [Map] [Gradient Map] to run the gradient called "AlphaLayersGradientB"
26. [Layer] [Stack] [Select Top Layer]
27. [Layer] [New from Visible]
28. [Layer] [Stack] [Select next layer]
29. [Layer] [Delete Layer] - Delete the four bottom layers
30. [Layer] [Delete Layer]
31. [Layer] [Delete Layer]
32. [Layer] [Delete Layer]
33. "Optional" change the resulting gradient interactively via [Colors] [Map] [Gradient Map]
0 x




Registered members enjoy ads-free content
User avatar
tim
Administrator
View: Showcase | Slideshow
Topic Posts: 3/5
Posts: 2162
Joined: 26 Sep 2016, 00:16
Cash on hand: 7,946.37 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 1207
x 256
Contact:
Canada

Post#2 by tim » 21 Oct 2017, 02:19


I'll start working on it now.
0 x



aka Tin
Image gimplearn.net                                              

User avatar
tim
Administrator
View: Showcase | Slideshow
Topic Posts: 3/5
Posts: 2162
Joined: 26 Sep 2016, 00:16
Cash on hand: 7,946.37 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 1207
x 256
Contact:
Canada

Post#3 by tim » 21 Oct 2017, 03:50


Please give this a try: viewtopic.php/Blend-2-Alpha-Layers-Scri ... 226#p11226
I added steps
#26.B) Tin Tran "I think PegLeg44 forgot to turn on visibility back on for the top layer"
##32.B) Selects none so the the optional gradient map would work on whole image.
0 x



aka Tin
Image gimplearn.net                                              

User avatar
Pegleg44

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

Post#4 by Pegleg44 » 21 Oct 2017, 04:55


Well it took me a week to put the process together in the shortest way possible and it only took you 90 minutes to make the script. You're pretty fast. I used it a little bit and it sure is nice not to have to do the whole thing manually. Just draw some layers and hit the button. Nice!

Thanks! it works great!
0 x




User avatar
tim
Administrator
View: Showcase | Slideshow
Topic Posts: 3/5
Posts: 2162
Joined: 26 Sep 2016, 00:16
Cash on hand: 7,946.37 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 1207
x 256
Contact:
Canada

Post#5 by tim » 21 Oct 2017, 05:05


Well you put the process together nicely so it made scripting a breeze.
0 x



aka Tin
Image gimplearn.net                                              

Post Reply

Last 20 Members Who Visited This Topic

User avatar gnerd (5), User avatar Pat625 (3), User avatar trandoductin (1), User avatar tim (18), User avatar RJKD (1), User avatar Pegleg44 (6)

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

Who is online

Users browsing this forum: No registered users and 1 guest