ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

RGB to HEX value #ffaadd to Text Source Layer Expression/Extendscript

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
joseph chung
RGB to HEX value #ffaadd to Text Source Layer Expression/Extendscript
on Feb 21, 2017 at 7:12:43 pm

Hi, I am trying to write an expression that will spit out #HEX value to a text layer source. The RGBA color will come from a fill color on a solid layer.

I cannot find anything to convert RGB to a HEX value only rgb to hsl.

Is this even possible through expression or extendscript?

This is what I have so far, which will spit out RGBA values from converting rgbtohsl and then back to hsltorgb*255

Any help is appreciated. Please feel free to email me, jchung@guidespark.com.

Joe

in_rgb = thisComp.layer("controller").effect("color_04")("Color");
in_hsl = rgbToHsl(in_rgb);
new_hue = (in_hsl[0] + 0) % 1;
new_sat = in_hsl[1] * ((thisComp.layer("color_04_tint").effect("saturation")("Slider")/100)+1);
new_lightness = in_hsl[2] * ((thisComp.layer("color_04_tint").effect("brightness")("Slider")/100)+1);
mod_hsl = [new_hue, new_sat, new_lightness, in_hsl[3]];

src = hslToRgb(mod_hsl) * 255;


Return to posts index

Dan Ebberts
Re: RGB to HEX value #ffaadd to Text Source Layer Expression/Extendscript
on Feb 21, 2017 at 9:14:36 pm

This might be helpful:

theColor = thisComp.layer("controller").effect("color_04")("Color");
r = Math.round(theColor[0]*255);
g = Math.round(theColor[1]*255);
b = Math.round(theColor[2]*255);
str = (r*65536 + g*256 + b).toString(16);
if (str.length < 6) str = "0" + str;
str


Dan



Return to posts index

joseph chung
Re: RGB to HEX value #ffaadd to Text Source Layer Expression/Extendscript
on Feb 21, 2017 at 9:41:51 pm

Thank you so much Mr. Ebberts! Works beautifully.

PS: I am a big fan of yours! Read so many threads with your replies of wisdom.

Joe


Return to posts index


Dan Ebberts
Re: RGB to HEX value #ffaadd to Text Source Layer Expression/Extendscript
on Feb 21, 2017 at 10:44:58 pm

Sorry, that one wasn't quite right. This is better:

theColor = thisComp.layer("controller").effect("color_04")("Color");
r = Math.round(theColor[0]*255).toString(16)
if (r.length < 2) r = "0" + r;
g = Math.round(theColor[1]*255).toString(16)
if (g.length < 2) g = "0" + g;
b = Math.round(theColor[2]*255).toString(16)
if (b.length < 2) b = "0" + b;
r+g+b


P.S. Thanks for the kind words!

Dan



Return to posts index

joseph chung
Re: RGB to HEX value #ffaadd to Text Source Layer Expression/Extendscript
on Feb 21, 2017 at 11:01:20 pm

Thank you sir!

I was going to ask what this conversion was, str = (r*65536 + g*256 + b).toString(16); but it looks like your new one handles it differently. Works awesome thank you so much!

Joe


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]