Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AlmightyOatmeal/eda216fa6e20c598a43e26162a9ed6b6 to your computer and use it in GitHub Desktop.
Save AlmightyOatmeal/eda216fa6e20c598a43e26162a9ed6b6 to your computer and use it in GitHub Desktop.
Python one-liners
# Base64 encode an image
$ echo "geek_ninja-glow.png" | python -c 'import base64, mimetypes, os, sys; filename=os.path.abspath(sys.stdin.read().strip()); file_mime=mimetypes.guess_type(filename, strict=True)[0]; file_data=base64.b64encode(open(filename, "rb").read()); print(""); print("<img src=\"data:{};base64,{}\">".format(file_mime, file_data))'

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...<snip>...yFo9lYcuhxyAAAAAElFTkSuQmCC">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment