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:
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).
Result
Now Data URL written to output_image.txt
can be used as embeded resource on web page, eg.
<html>
<body>
<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmc ...">
</body>
</html>
Screenshot: