Other Stuff

Making Data URI

The data URI scheme is a uniform resource identifier (URI) scheme that provides a way to include data in-line in web pages as if they were external resources. This technique allows normally separate elements such as images and style sheets to be fetched in a single HTTP request, which may be more efficient than multiple HTTP requests.

You can use some web-service like http://dataurl.net to convert the data to the DataURI scheme. This is ok, but an Internet connection is needed, when you don't have access you can't use the tool.

The best way is do it locally, luckily for OS X and Linux there is a cli tool that can convert data in with single a command. That tool is called datauri-cli.

Install it by issuing a:

npm install -g datauri-cli

Converting Images

datauri image.png

The command above will output the image as datauri to stdout. If you want to copy directly into the clipboard use this instead:

datauri image.png --copy

Converting to CSS

datauri image.png --css

The command above will output the image as datauri to stdout as CSS. You can also copy it using:

datauri image.png --css --copy

Another option is to create/update .css files directly. Can be done with:

datauri image.png --css=style.css

Finally it is possible to define the class to dump the data scheme in or specify parameters such as width or height, like this:

datauri image.png --css --class=MyNewClass

datauri image.png --css --width --height

datauri image.png --css --background-size

The program's project is hosted by Github, here: https://github.com/data-uri/datauri

Output Examples

Image to DataURI
  mach7 [~/Desktop] $ datauri Image.png


  mach7 [~/Desktop] $
Image to DataURI CSS
   mach7 [~/Desktop] $ datauri Image.png --css

.Image {
    background-image: url('data:image/png;base64,iVBORw0KGgoAAA

  mach7 [~/Desktop] $
The Help
  mach7 [~/Desktop] $ datauri -h

Data-uri usage:

datauri <target_file>
datauri <target_file> --css
datauri <target_file> --copy
datauri <target_file> --css --copy
datauri <target_file> --css=<css_output>
datauri <target_file> --css=<css_output> --class=<css_class_name>
datauri <target_file> --css=<css_output> --class=<css_class_name> --width --height
datauri <target_file> --css=<css_output> --class=<css_class_name> --background-size

  mach7 [~/Desktop] $