Learn R Programming

knitr (version 1.31)

image_uri: Encode an image file to a data URI

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

image_uri(f)

Arguments

f

Path to the image file.

Value

The data URI as a character string.

References

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

Examples

Run this code
# NOT RUN {
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
}
# }

Run the code above in your browser using DataLab