Lasso Soft Inc. > Home

[pk_blackorwhitefromhex]

Linkpk_blackorwhitefromhex
AuthorPier Kuipers
CategoryString
Version8.5.x
LicensePublic Domain
Posted06 Feb 2012
Updated06 Feb 2012
More by this author...

Description

Takes an arbitrary hexadecimal background colour value and returns "black" or "white" as the most suitable font colour to be used against this background. Requires [pk_hextorgb]

Sample Usage

pk_blackorwhitefromhex('a70e13');
-> 'white'

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

//  Takes an arbitrary hexadecimal background colour value and returns "black" or "white" as the most suitable font colour to be used against this background.
//  Requires [pk_hextorgb]
define_tag('blackorwhitefromhex',     
    -namespace='pk_',    
    -required='color');    
    local('output'='black');        
    local('tmparray'=((pk_hextorgb(#color))->split(' ')));
    local('i');
    local('value'=integer);
    iterate(#tmparray, #i);
        #value += (integer(#i));
    /iterate;
    ((#value / 3) < 128) ? #output = 'white';
    return(@#output);
/define_tag;

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft