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
|
<?lassoscript
if: !(lasso_tagexists:'pk_hextorgb');
define_tag: 'hextorgb', -namespace='pk_',
-required='hex',
-description='converts a hex string to an rgb colour value';
local:'hexvalues' = '0123456789abcdef';
local:'myhex' = (string_removeleading:#hex, -pattern='#');
#myhex -> (uppercase);
if: (#myhex -> size == 3);
local:'temphex'=string;
loop: 3;
#temphex += (#myhex -> get:(loop_count));
#temphex += (#myhex -> get:(loop_count));
/loop;
#myhex = #temphex;
else: (#myhex -> size > 6) || (#myhex -> size < 6);
#myhex = 'ffffff';
/if;
loop: 6;
if:!(#hexvalues -> contains:(#myhex -> get:(loop_count)));
#myhex = 'ffffff';
/if;
/loop;
local:'rgbstring'=string;
local:'looparray'= (: 1, 3, 5);
iterate: #looparray, local:'tmp';
local:'mydecimal'=(#hexvalues -> find:(#myhex -> get:(#tmp)));
local:'tens'=((integer:(#mydecimal - 1)) * 16);
local:'ones'=(integer:(#hexvalues -> find:(#myhex -> get:(#tmp + 1))));
#rgbstring += (string:(#tens + (#ones - 1))) + ' ';
/iterate;
#rgbstring -> trim;
return:#rgbstring;
/define_tag;
/if;
?>
|