encode a png file as a img data uri

Share:

Description

This creates html code to embed a png file into an html document.

Usage

1
img(file, Rd = FALSE, alt = "image" )

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 img function

\Sexpr[results=rd, stage=build, echo=FALSE]{ library( base64 ) 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() img( 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 <romain@r-enthusiasts.com>

References

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

See Also

encode 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()
img( pngfile )

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.