Page 1 of 1

Create a gradient with 16bit color values

Posted: 2015-01-14T12:21:36-07:00
by Maniac
I've got a background template and an image using this background. On the lower half of the background there is a gradient placed on the image.
I want to reproduce the gradient on the template matching the color in the image as good as possible.

For this I first tried to figure out which blending method was used to blend the gradient to the background. It seems it was a multiply. To get this information I simply took a color value from the background and from the same position from the picture. Now I used the formula:

Code: Select all

Result = (Source * Gradient) / 255
I did this for several colors and always the values I received for RGB are mostly identical (they vary bei 1-2 sometimes), so I think I got the correct gradient color.

My issue with this is, the gradient color I got this way has values greater than 255. This is my color in dec 177 299 320.

For my next steps I want to create a radiant with convert like

Code: Select all

convert -size 1000x1000 gradient:none-#2b0140 test.png
and then combine it with composite multiply.

I think I need a gradient created with 16bit color values instead of 8bit, but I can't find a way to tell gradient my color values.

Re: Create a gradient with 16bit color values

Posted: 2015-01-14T16:46:18-07:00
by fmw42

Re: Create a gradient with 16bit color values

Posted: 2015-01-14T17:23:45-07:00
by snibgo
Maniac wrote:convert -size 1000x1000 gradient:none-#2b0140 test.png
Sadly, that won't work. Making a gradient from "none" to an opaque colour won't do what we might want.

Code: Select all

f:\web\im>%IM%convert -size 1x10 gradient:none-#123 txt:
# ImageMagick pixel enumeration: 1,10,65535,srgba
0,0: (0%,0%,0%,0)  #0000000000000000  none
0,1: (6.66667%,13.3333%,20%,0.111116)  #1111222233331C72  srgba(6.66667%,13.3333%,20%,0.111116)
0,2: (6.66667%,13.3333%,20%,0.222217)  #11112222333338E3  srgba(6.66667%,13.3333%,20%,0.222217)
0,3: (6.66667%,13.3333%,20%,0.333333)  #1111222233335555  srgba(17,34,51,0.333333)
0,4: (6.66667%,13.3333%,20%,0.44445)  #11112222333371C7  srgba(6.66667%,13.3333%,20%,0.44445)
0,5: (6.66667%,13.3333%,20%,0.55555)  #1111222233338E38  srgba(6.66667%,13.3333%,20%,0.55555)
0,6: (6.66667%,13.3333%,20%,0.666667)  #111122223333AAAA  srgba(17,34,51,0.666667)
0,7: (6.66667%,13.3333%,20%,0.777783)  #111122223333C71C  srgba(6.66667%,13.3333%,20%,0.777783)
0,8: (6.66667%,13.3333%,20%,0.888884)  #111122223333E38D  srgba(6.66667%,13.3333%,20%,0.888884)
0,9: (6.66667%,13.3333%,20%,1)  #111122223333  srgba(17,34,51,1)
We get a proper gradation in the alpha channel, but not the colour channels.

Re: Create a gradient with 16bit color values

Posted: 2015-01-14T18:41:19-07:00
by fmw42
I believe that this works with 16-bit hex values. Snibgo, correct me if I am wrong.

Code: Select all

convert -size 1x10 gradient:"#0000000000000000-#2b2b01014040ffff" txt:
# ImageMagick pixel enumeration: 1,10,65535,srgba
0,0: (0%,0%,0%,0)  #0000000000000000  none
0,1: (16.8627%,0.392157%,25.098%,0.111116)  #2B2B010140401C72  srgba(16.8627%,0.392157%,25.098%,0.111116)
0,2: (16.8627%,0.392157%,25.098%,0.222217)  #2B2B0101404038E3  srgba(16.8627%,0.392157%,25.098%,0.222217)
0,3: (16.8627%,0.392157%,25.098%,0.333333)  #2B2B010140405555  srgba(43,1,64,0.333333)
0,4: (16.8627%,0.392157%,25.098%,0.44445)  #2B2B0101404071C7  srgba(16.8627%,0.392157%,25.098%,0.44445)
0,5: (16.8627%,0.392157%,25.098%,0.55555)  #2B2B010140408E38  srgba(16.8627%,0.392157%,25.098%,0.55555)
0,6: (16.8627%,0.392157%,25.098%,0.666667)  #2B2B01014040AAAA  srgba(43,1,64,0.666667)
0,7: (16.8627%,0.392157%,25.098%,0.777783)  #2B2B01014040C71C  srgba(16.8627%,0.392157%,25.098%,0.777783)
0,8: (16.8627%,0.392157%,25.098%,0.888884)  #2B2B01014040E38D  srgba(16.8627%,0.392157%,25.098%,0.888884)
0,9: (16.8627%,0.392157%,25.098%,1)  #2B2B01014040  srgba(43,1,64,1)

Re: Create a gradient with 16bit color values

Posted: 2015-01-15T05:05:52-07:00
by snibgo
fmw42 wrote:I believe that this works with 16-bit hex values. Snibgo, correct me if I am wrong.
Your result is like mine: it gives graduation in alpha but not colour.

Further experiments show this happens when the value of either alpha is zero. If neither alpha is zero, we get graduation in both alpha and colour, which is what I would always expect.

Code: Select all

convert -size 1x10 gradient:rgba(10,20,30,0.1)-rgba(20,30,40,0.8) txt:
# ImageMagick pixel enumeration: 1,10,65535,srgba
0,0: (3.92157%,7.84314%,11.7647%,0.0999924)  #0A0A14141E1E1999  srgba(3.92157%,7.84314%,11.7647%,0.0999924)
0,1: (5.88235%,9.80392%,13.7255%,0.177768)  #0F0F191923232D82  srgba(5.88235%,9.80392%,13.7255%,0.177768)
0,2: (6.64988%,10.5715%,14.493%,0.255543)  #11061B10251A416B  srgba(6.64988%,10.5715%,14.493%,0.255543)
0,3: (7.05882%,10.9804%,14.902%,0.333333)  #12121C1C26265555  srgba(18,28,38,0.333333)
0,4: (7.31365%,11.2352%,15.1568%,0.411109)  #12B91CC326CD693E  srgba(7.31365%,11.2352%,15.1568%,0.411109)
0,5: (7.48608%,11.4076%,15.3292%,0.488884)  #132A1D34273E7D27  srgba(7.48608%,11.4076%,15.3292%,0.488884)
0,6: (7.61273%,11.5343%,15.4559%,0.566659)  #137D1D8727919110  srgba(7.61273%,11.5343%,15.4559%,0.566659)
0,7: (7.70733%,11.6289%,15.5505%,0.64445)  #13BB1DC527CFA4FA  srgba(7.70733%,11.6289%,15.5505%,0.64445)
0,8: (7.7821%,11.7037%,15.6252%,0.722225)  #13EC1DF62800B8E3  srgba(7.7821%,11.7037%,15.6252%,0.722225)
0,9: (7.84314%,11.7647%,15.6863%,0.8)  #14141E1E2828CCCC  srgba(20,30,40,0.8)
A workaround, to get graduation in both colour and alpha where one end is fully transparent, is to make a separate graduation for alpha:

Code: Select all

convert -size 1x10 gradient:#000-#2b0140 gradient:black-white -compose CopyOpacity -composite txt:
# ImageMagick pixel enumeration: 1,10,65535,srgba
0,0: (0%,0%,0%,0)  #0000000000000000  none
0,1: (1.87381%,0.0442512%,2.78935%,0.111116)  #04CC001D07241C72  srgba(1.87381%,0.0442512%,2.78935%,0.111116)
0,2: (3.74762%,0.0869764%,5.57717%,0.222217)  #099800390E4738E3  srgba(3.74762%,0.0869764%,5.57717%,0.222217)
0,3: (5.62142%,0.131228%,8.36652%,0.333333)  #0E640056156B5555  srgba(5.62142%,0.131228%,8.36652%,0.333333)
0,4: (7.49523%,0.173953%,11.1543%,0.44445)  #133000721C8E71C7  srgba(7.49523%,0.173953%,11.1543%,0.44445)
0,5: (9.36751%,0.218204%,13.9437%,0.55555)  #17FB008F23B28E38  srgba(9.36751%,0.218204%,13.9437%,0.55555)
0,6: (11.2413%,0.260929%,16.7315%,0.666667)  #1CC700AB2AD5AAAA  srgba(11.2413%,0.260929%,16.7315%,0.666667)
0,7: (13.1151%,0.30518%,19.5209%,0.777783)  #219300C831F9C71C  srgba(13.1151%,0.30518%,19.5209%,0.777783)
0,8: (14.9889%,0.347906%,22.3087%,0.888884)  #265F00E4391CE38D  srgba(14.9889%,0.347906%,22.3087%,0.888884)
0,9: (16.8627%,0.392157%,25.098%,1)  #2B2B01014040  srgba(43,1,64,1)