Images as Code

Today I wanted to encode an image as Base64 in order to add it to an image HTML tag src.I use a Mac for the majority of my development and in Terminal it's a one liner:

$ cat /path/to/img/file | base64
SGVsbG8gVGVjaFJhbQo=

This is also like ot be the case in Linux too and wile I can appreciate the usefulness of knowing how to do this in Java or Python, it's always handy to know the command line approach.

First appeared on Trusty Interior, last update 26 Nov 2023