| upload_imgur | R Documentation |
This function uses the curl package or the system command curl
(whichever is available) to upload a image to https://imgur.com.
upload_imgur(
file,
key = env_option("xfun.upload_imgur.key"),
use_curl = loadable("curl"),
include_xml = FALSE
)
file |
Path to the image file to be uploaded. |
key |
Client ID for Imgur. It can be set via either the global option
|
use_curl |
Whether to use the R package curl to upload the image.
If |
include_xml |
Whether to include the XML response in the returned value. |
One application is to upload local image files to Imgur when knitting a
document with knitr: you can set
knitr::opts_knit$set(upload.fun = xfun::upload_imgur), so the output
document does not need local image files any more, and it is ready to be
published online.
Note that this makes the output self-contained only in the sense that the
images are loaded from imgur.com rather than from local files, so the single
output file can be shared without the accompanying image files. It does not
make the file work offline. If you want a stricter form of self-containedness
that does not require an Internet connection (i.e., the images are base64
encoded and embedded in the output), do not use this function, and instead
use the self_contained option of the output format (e.g., in the YAML
metadata of an R Markdown document).
A character string of the link to the image. If include_xml = TRUE,
this string carries an attribute named XML, which is the XML response
from Imgur (it will be parsed by xml2 if available). See Imgur API in
the references.
Please register your own Imgur application to get your client ID. You can certainly use mine, but this ID is in the public domain and it might reach Imgur's rate limit if too many people are using it in the same time period or someone is trying to upload too many images at once.
Yihui Xie, adapted from the imguR package by Aaron Statham
A demo: https://yihui.org/knitr/demo/upload/
## Not run:
f = tempfile(fileext = ".png")
png(f); plot(rnorm(100), main = R.version.string); dev.off()
res = imgur_upload(f, include_xml = TRUE)
res # link to original URL of the image
xfun::attr2(res, "XML") # all information
if (interactive()) browseURL(res)
# to use your own key
options(xfun.upload_imgur.key = "your imgur key")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.