Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Convert An Image To base64 On The Command Line

Use the `base64` command with the `< filename` operator to convert an image to base64 and save the string in a file:

Code

base64 IMAGE_FILE.jpg > OUTPUT.txt

You can also export it into an environmental variable for use in other scripts

Code

export IMAGE_STRING=$(base64 IMAGE_FILE.jpg)
echo $IMAGE_STRING