[pk_hextorgb]

Description

Link: [pk_hextorgb]
Author: Pier Kuipers
Category: String
Version: 8.x
License: Public Domain
Posted: Jan. 10, 2006
Updated: Jan. 16, 2006
More by this author...
Tag accepts a HTML hexadecimal colour value such as "#f45a49" or "#FFF" and converts it to a space delimited RGB value such as "255 255 255".

Parameters

none


Sample Usage

[pk_hextorgb:'#fff']
-> 255 255 255
						

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.
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;

?>

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net