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

Mike Procunier
Re: RGB to HEX value #ffaadd to Text Source Layer Expression/Extendscript
on Jan 25, 2018 at 4:32:07 pm

Hi,
I'm trying to do the opposite of this expression. I'd like to take a HEX value from a text layer source and have the expression return an RGB value for a Fill effect. I found a hex to rgb expression that you posted in another forum and tried to adapt it for my purposes but its not working. Any ideas?

function hexToColor(theHex){

theHex=thisComp.layer("^COLOR").text.sourceText;

theHex = parseInt(theHex,16);

var r = theHex >> 16;

var g = (theHex & 0x00ff00) >> 8;

var b = theHex & 0xff;

return [r/255,g/255,b/255];
}




Return to posts index


Dan Ebberts
Re: RGB to HEX value #ffaadd to Text Source Layer Expression/Extendscript
on Jan 25, 2018 at 5:43:49 pm

Try it this way:


function hexToColor(theHex){
var r = theHex >> 16;
var g = (theHex & 0x00ff00) >> 8;
var b = theHex & 0xff;
return [r/255,g/255,b/255,1];
}

txt = thisComp.layer("^COLOR").text.sourceText;
myHex = (parseInt(txt,16));
hexToColor(myHex);



Dan



Return to posts index

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