Skip to content

Commit b20d636

Browse files
authored
Added Base64 Image Support
1 parent 8b5874a commit b20d636

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ var HouseIconSVG := GetFontAwesomeIconPathData('house', 24, 'purple');
6262
var ValveSteamIconSVG := GetFontAwesomeIconPathData('steam', 24, '#800080');
6363
var BrushIconSVG := GetFontAwesomeIconPathData('brush', 24, 'purple');
6464
```
65+
66+
### SVG Base64 Image
67+
68+
```pascal
69+
uses uFontAwesomeIcons
70+
71+
...
72+
73+
// Returns SVG Base64 Image:
74+
var HouseIconSVGBase64 := GetFontAwesomeIconBase64('house');
75+
var ValveSteamIconSVGBase64 := GetFontAwesomeIconBase64('steam');
76+
var BrushIconSVGBase64 := GetFontAwesomeIconBase64('brush');
77+
78+
// Returns SVG Base64 Image with Width/Height set to 24:
79+
var HouseIconSVGBase64 := GetFontAwesomeIconBase64('house', 24);
80+
var ValveSteamIconSVGBase64 := GetFontAwesomeIconBase64('steam', 24);
81+
var BrushIconSVGBase64 := GetFontAwesomeIconBase64('brush', 24);
82+
83+
// Returns SVG Base64 Image with Width/Height set to 24 and color set to purple (#800080):
84+
var HouseIconSVGBase64 := GetFontAwesomeIconBase64('house', 24, 'purple');
85+
var ValveSteamIconSVGBase64 := GetFontAwesomeIconBase64('steam', 24, '#800080');
86+
var BrushIconSVGBase64 := GetFontAwesomeIconBase64('brush', 24, 'purple');
87+
```
88+
6589
Other ways to use Font Awesome Icons: [https://fontawesome.com/docs](https://fontawesome.com/docs)
6690

6791
## License

uFontAwesomeIcons.pas

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ interface
55

66
uses
77
System.SysUtils
8-
{$IFNDEF WEBLIB}
8+
{$IFDEF WEBLIB}
9+
, Web
10+
{$ELSE}
911
, System.RegularExpressions
10-
{$IFEND}
12+
, System.NetEncoding
13+
{$ENDIF}
1114
;
1215

1316
type
@@ -20,7 +23,8 @@ TFontAwesomeIcon = record
2023
function GetFontAwesomeIcon(IconName: String; IconSize: Cardinal = 16; HTMLColor: String = ''): String;
2124
{$IFNDEF WEBLIB}
2225
function GetFontAwesomeIconPathData(IconName: String; IconSize: Cardinal = 16; HTMLColor: String = ''): String;
23-
{$IFEND}
26+
{$ENDIF}
27+
function GetFontAwesomeIconBase64(IconName: String; IconSize: Cardinal = 16; HTMLColor: String = ''): String;
2428

2529
const
2630
FontAwesomeIconsArray: array[0..2023] of TFontAwesomeIcon = (
@@ -16627,7 +16631,7 @@ function GetFontAwesomeIconPathData(IconName: String; IconSize: Cardinal; HTMLCo
1662716631
Result := PathData;
1662816632
end;
1662916633
end;
16630-
{$IFEND}
16634+
{$ENDIF}
1663116635

1663216636
function GetFontAwesomeIcon(IconName: String; IconSize: Cardinal; HTMLColor: String): String;
1663316637
const
@@ -16651,4 +16655,14 @@ function GetFontAwesomeIcon(IconName: String; IconSize: Cardinal; HTMLColor: Str
1665116655
end;
1665216656
end;
1665316657

16658+
function GetFontAwesomeIconBase64(IconName: String; IconSize: Cardinal; HTMLColor: String): String;
16659+
begin
16660+
Result := '';
16661+
{$IFDEF WEBLIB}
16662+
Result := 'data:image/svg+xml;base64,' + window.btoa(GetFontAwesomeIcon(IconName, IconSize, HTMLColor));
16663+
{$ELSE}
16664+
Result := 'data:image/svg+xml;base64,' + TNetEncoding.Base64.Encode(GetFontAwesomeIcon(IconName, IconSize, HTMLColor));
16665+
{$ENDIF}
16666+
end;
16667+
1665416668
end.

0 commit comments

Comments
 (0)