Encode a PNG File as a IMG Data URI

Description

Create HTML code to embed a PNG file into an HTML document.

Usage

1
b64img(file, Rd = FALSE, alt = file)

Arguments

file

PNG file to translate into a data URI.

Rd

If TRUE, extra markup is added to facilitate inclusion of the image in an Rd file.

alt

Alternate text.

Details

The following graph is embedded in the document using the b64img function.

\Sexpr[results=rd, stage=build, echo=FALSE]{ library(htmltools) library(grDevices) library(graphics) library(stats) pngfile <- tempfile() png(pngfile, width = 600, height = 400) plot(1:100, rnorm(100), pch = 21, bg = "red", cex = 2) dev.off() b64img(pngfile, Rd = TRUE) }

Value

The HTML code.

Note

No checking on the file is performed, so it is up to the user to make sure the input file is indeed a PNG file.

Author(s)

Romain Francois

References

Wikipedia entry for data URI http://en.wikipedia.org/wiki/Data_URI_scheme.

See Also

b64encode is used to encode the file

Examples

1
2
3
4
5
6
7
8
## Not run: 
pngfile <- tempfile()
png(pngfile, width = 600, height = 600)
plot(1:100, rnorm(100), pch = 21, bg = "red", cex = 2)
dev.off()
b64img(pngfile)

## End(Not run)