Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions RGB to HEX value #ffaadd to Text Source Layer Expression/Extendscript

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

    Posted by Joseph Chung on February 21, 2017 at 7:12 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, jc****@********rk.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;

    Dan Ebberts replied 8 years, 3 months ago 3 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    February 21, 2017 at 9:14 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

  • Joseph Chung

    February 21, 2017 at 9:41 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

  • Dan Ebberts

    February 21, 2017 at 10:44 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

  • Joseph Chung

    February 21, 2017 at 11:01 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

  • Mike Procunier

    January 25, 2018 at 4:32 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];
    }

  • Dan Ebberts

    January 25, 2018 at 5:43 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

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy