Last active
August 5, 2019 17:42
-
-
Save phillip-boombox/93aa465ee0fc3c3b0535e852e5ee11ca to your computer and use it in GitHub Desktop.
Convert an image to base64 data URI that's then copied to the clipboard.
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
#!/bin/bash | |
# Create a base64 data URI from an image and copy it to clipboard. | |
# Uses OpenSSL to create the base64 representation. | |
the_mimetype=$(file -bN --mime-type "$1") | |
the_content=$(openssl base64 < "$1" | tr -d '\n') | |
# Use printf instead of echo to avoid the ending newline | |
printf "data:$the_mimetype;base64,$the_content" | pbcopy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To Use
cd
into the folder.chmod +x img2datauri.sh
../img2datauri.sh image.png
. Replaceimage.png
with proper filename. Data URI can then be pasted into browser dev tools to see the new image.