- Automatically detects the MIME type of the image (e.g.,
image/png,image/jpeg). - Encodes the image to base64 and outputs it in a single line.
- Generates a complete HTML
<img>tag with the base64-encoded image for embedding in Markdown or HTML files. - Automatically copies the generated
tag to the clipboard using cliphist.
- The script handles large hashes by using a temporary file to manage clipboard operations.
- Bash (Unix/Linux environment)
filecommand (for detecting MIME type)base64command (for encoding)- cliphist (the clipboard manager that I'm using)
-
Clone the repository or download the script.
-
Make the script executable:
chmod +x img2md
Tip
Move the script to a directory in your $PATH for easy access:
sudo mv img2md /usr/local/bin/- Just run the script with the image as argument:
img2md <image-file>- This will output:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUg..." alt="image" />