Convert an image to a Base64 data URI
Inlining a small icon as a data URI removes an HTTP request, which is worth doing for things like a loading spinner in a plugin. Base64 adds roughly a third to the file size, so it only pays below a few kilobytes.
Common questions
When is a data URI worth it?
Below about 4KB, for images used immediately on page load. Above that the Base64 overhead and the loss of separate caching cost more than the saved request.
Can I use this in a WordPress theme?
Yes — paste the string into a CSS background-image, or into an img src. It works anywhere a URL does, and needs no media library entry.
