Page 1 of 1

Blend2AlphaLayers - Script Idea

Posted: 21 Oct 2017, 01:20
by Pegleg44
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.


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


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


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


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
# Created by Tin Tran
# Comments directed to or or or
# 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
# GNU General Public License for more details.
# To view a copy of the GNU General Public License
# visit:
# ------------
#| 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) :
	#New Darken Layer from Visible
	#Here's the steps:
#0. [Select] [Select None]
#1. [Layer] [New Layer from Visible]
	new_visible = pdb.gimp_layer_new_from_visible(image,image,"new from visible");
#2. [Layer] [ Transparency] [ Color to Alpha]
#3. [Tools] [ Default Colors] the next step needs a white background layer active
#4. [Layer] [Transparency] [ Semi-Flatten]
#5. Set colors back to what they were before. This was done on a different script but doesn't really need to be included.
#6. Lock the Alpha Channel (Button in the Layers Dock-able dialog.
#7. Layer mode to [Darken Only]
#8. [Layer] [Transparency] [Alpha to Selection]
#9. [Layer] Crop to Selection]
#The tool tip could be: Combines Height Layers into One Cropped Darken Only Layer


	"Combines Height Layers into One Cropped Darken Only Layer",
	"Combines Height Layers into One Cropped Darken Only Layer",
	"Tin Tran",
	"Tin Tran",
	"<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


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]

Re: Blend2AlphaLayers - Script Idea

Posted: 21 Oct 2017, 02:19
by tim
I'll start working on it now.

Re: Blend2AlphaLayers - Script Idea

Posted: 21 Oct 2017, 03:50
by tim
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.

Re: Blend2AlphaLayers - Script Idea

Posted: 21 Oct 2017, 04:55
by Pegleg44
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!

Re: Blend2AlphaLayers - Script Idea

Posted: 21 Oct 2017, 05:05
by tim
Well you put the process together nicely so it made scripting a breeze.