EN
Bash - convert svg to base64 data url
7 points
In this short article we would like to show how to convert *.svg
file to Data URL encoded with base64 using Bash (under Linux or Git for Windows).
Quick solution:
xxxxxxxxxx
1
echo "data:image/svg+xml;base64,$(cat input_image.svg | base64 | tr -d '\r\n')" > output_image.txt
Where: input_image.svg
is converted to output_image.txt
(Data URL with base64).
Now Data URL written to output_image.txt
can be used as embeded resource on web page, eg.
xxxxxxxxxx
1
<html>
2
<body>
3
<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmc ...">
4
</body>
5
</html>
Screenshot:
