image_uri: Encode an image file to a data URI

Description Usage Arguments Value Author(s) References Examples

View source: R/utils.R

Description

This function is the same as xfun::base64_uri() (only with a different function name). It can encode an image file 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

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

Examples

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

Example output



knitr documentation built on Jan. 27, 2021, 5:09 p.m.