image_uri: Encode an image file to a data URI

Description Usage Arguments Value Author(s) References Examples

View source: R/utils-base64.R

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

1

Arguments

f

Path to the image file.

Value

The data URI as a character string.

Author(s)

Wush Wu and Yihui Xie

References

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

Examples

1
2
3
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

yihui/knitr documentation built on Dec. 11, 2018, 3:41 a.m.