Languages
[Edit]
EN

Bash - convert svg to base64 data url

7 points
Created by:
Root-ssh
177650

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:

SVG conversion to base64 Data URL under Bash
SVG conversion to base64 Data URL under Bash
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Bash

Bash - convert svg to base64 data url
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join