1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
<?LassoScript
/*
================================================================================
RGB to Hex Custom Tag
for use with Lasso Professional 7
Converts a comma delimited string holding RGB values into its Hex equivalent.
Usage:
[pk_rgbtohex: <string>]
Example:
[pk_rgbtohex: '255, 24, 189'] -> '#FF18BD'
[pk_rgbtohex: '255, 24, 189', -nohash] -> 'FF18BD'
Based on http://www.javascripter.net/faq/rgbtohex.htm
Written by Pier Kuipers, Dublin
September 2004
pier@visualid.com
http://www.pierkuipers.com/lasso.html
================================================================================
*/
if: !(lasso_tagexists:'pk_rgbtohex');
define_tag:'pk_rgbtohex',
-required='rgbString',
-optional='nohash';
If:!(#rgbString -> (isa:'string'));
local:'thisHex' = 'error';
Else;
local:'rgbArray' = #rgbString -> Split:',';
If:(#rgbArray -> size == 3);
local:'thisHex' = string;
local:'hexList' = (:'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
Iterate: #rgbArray, local:'thisN';
#thisN = (integer:#thisN);
If:(#thisN == 0);
#thisHex += '00';
Else;
#thisN = (Math_Max: 0, #thisN);
#thisN = (Math_Min: #thisN, 255);
#thisN = (Math_Round: #thisN, 1);
local:'thisN2' = (#thisN);
#thisN = (((#thisN - (#thisN % 16)) / 16) + 1);
#thisN2 = ((#thisN2 % 16) + 1);
#thisHex += (#hexList -> get: #thisN);
#thisHex += (#hexList -> get: #thisN2);
/If;
/Iterate;
Else;
local:'thisHex' = 'error';
/If;
/If;
If:!(local_defined:'nohash');
#thisHex = ('#' + #thisHex);
/If;
return: #thisHex;
/define_tag;
/If;
?>
|