Languages
[Edit]
EN

Bash - convert webp image to base64 data URL

10 points
Created by:
Zeeshan-Peel
850

In this short article, we would like to show how to convert *.webp file to Data URL encoded with base64 using Bash.

Quick solution:

echo -n "data:image/webp;base64,$(cat input_image.webp | base64 | tr -d '\r\n')" > output_image.txt

Where: input_image.webp is converted to output_image.txt (Data URL with base64 inside).

 

Example result

Now Data URL is written to output_image.txt can be used as an embedded resource on the web page, eg.

<html>
<body>
  <img src="data:image/webp;base64,UklGRlAGAABXRUJQVlA4WAoAAAAIAAAAhQEAhQEAVl ...">
</body>
</html>

 

See also

  1. Bash - convert png image to base64 data url

  2. Bash - convert jpg image to base64 data url

  3. Bash - remove new line characters from file with tr command
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.
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