7

There are online tools like duri.me that allow to create a Data URI from an image file. Are there any tools that run locally on Linux to do the same?

10

Data URIs are usually just base64-encoded with the MIME-type stuck at the front. I use this homegrown script, which takes the filename as its first and only parameter and returns the data uri, already wrapped in url('data:'):

[0 1026 8:29:38] ~ % cat $(which cssify.sh)
#!/bin/sh
mimetype=$(file -bN --mime-type "$1")
content=$(base64 -w0 < "$1")
echo "url('data:$mimetype;base64,$content')"
  • I needed to replace -w0 with -b0 – thanksd Dec 12 '18 at 23:30

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.