Skip to content

Bash script to convert an image to a base64-encoded string and outputs it as an HTML <img> tag for easy embedding in Markdown.

License

Notifications You must be signed in to change notification settings

b0llull0s/img2md

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

img2md

  • 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.

Requirements

  • Bash (Unix/Linux environment)
  • file command (for detecting MIME type)
  • base64 command (for encoding)
  • cliphist (the clipboard manager that I'm using)

Installation

  1. Clone the repository or download the script.

  2. 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/

Usage

  • Just run the script with the image as argument:
img2md <image-file>
  • This will output:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUg..." alt="image" />

About

Bash script to convert an image to a base64-encoded string and outputs it as an HTML <img> tag for easy embedding in Markdown.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages