Created
May 7, 2024 19:50
-
-
Save AlmightyOatmeal/eda216fa6e20c598a43e26162a9ed6b6 to your computer and use it in GitHub Desktop.
Python one-liners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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