home ~ projects ~ socials

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:

base64 IMAGE_FILE.jpg > OUTPUT.txt

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

export IMAGE_STRING=$(base64 IMAGE_FILE.jpg)
echo $IMAGE_STRING
-- end of line --