image_uri {knitr}R Documentation

Encode an image file to a data URI

Description

This function takes an image file and uses the markdown package to encode it as a base64 string, which can be used in the img tag in HTML.

Usage

image_uri(f)

Arguments

f

the path to the image file

Value

a character string (the data URI)

Author(s)

Wush Wu and Yihui Xie

References

http://en.wikipedia.org/wiki/Data_URI_scheme

Examples

uri = image_uri(file.path(R.home("doc"), "html", "logo.jpg"))
cat(sprintf("<img src=\"%s\" />", uri), file = "logo.html")
if (interactive()) browseURL("logo.html")  # you can check its HTML source

[Package knitr version 1.15.20 Index]