img2base64 icon indicating copy to clipboard operation
img2base64 copied to clipboard

CLI tool to convert image to base64 encoded string for markdown

Img2base64

Convert this...

...into this

![](data:image/jpg;base64,/9j/4AAQSkZJRgABAQ...)

NOTE: GitHub strips base64 encoded images when rendering Markdown. Be sure to enable this when using your own renderer (Eg: Redcarpet with Jekyll).

Installation

Img2base64 is a gem. Build and install using rake.

$ git clone git://github.com/tatey/img2base64.git
$ rake install

Usage

Get the base64 encoded image in markdown and pipe output to your pasteboard on Mac OS X.

$ img2base64 ~/Desktop/grumpycat.jpg | pbcopy

Compatible with GIF, JPG and PNG.

Markdown

Type this

$ img2base64 ~/Desktop/grumpycat.jpg -f markdown

And get a Markdown image with the Data URI

![](data:image/jpg;base64,/9j/4AAQSkZJRgABAQ...)

HTML

Type this

$ img2base64 ~/Desktop/grumpycat.jpg -f html

And get a HTML image with the Data URI

<img src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQ...">

Data URI

Type this

$ img2base64 ~/Desktop/grumpycat.jpg

And get the raw Data URI string

data:image/jpg;base64,/9j/4AAQSkZJRgABAQ...

Developing and Testing

First, install the gem's development dependencies.

$ bundle

Then, run the test suite.

$ [bundle exec] rake

License

Copyright © 2016 Tate Johnson. Released under the MIT license. See LICENSE.