base64_uri: Generate the Data URI for a file

View source: R/base64.R

base64_uriR Documentation

Generate the Data URI for a file

Description

Encode the file in the base64 encoding, and add the media type. The data URI can be used to embed data in HTML documents, e.g., in the src attribute of the <img /> tag.

Usage

base64_uri(x, type = mime::guess_type(x))

Arguments

x

A file path.

type

The MIME type of the file, e.g., "image/png" for a PNG image file.

Value

A string of the form data:<media type>;base64,<data>.

Note

By default, this function requires the mime package to determine the MIME type of the file.

Examples

logo = xfun:::R_logo()
img = htmltools::img(src = xfun::base64_uri(logo), alt = "R logo")
if (interactive()) htmltools::browsable(img)

xfun documentation built on Nov. 17, 2022, 1:06 a.m.