imgur_upload: Upload an image to imgur.com

View source: R/utils-upload.R

imgur_uploadR Documentation

Upload an image to imgur.com

Description

This function uses the curl package to upload a image to https://imgur.com, and parses the XML response to a list with xml2, which contains information about the image on Imgur.

Usage

imgur_upload(
  file,
  key = xfun::env_option("knitr.imgur.key", "9f3460e67f308f6")
)

Arguments

file

Path to the image file to be uploaded.

key

Client ID for Imgur. It can be set via either the global option knitr.imgur.key or the environment variable R_KNITR_IMGUR_KEY (see [xfun::env_option()]). If neither is set, this uses a client ID registered by Yihui Xie.

Details

When the output format from knit() is HTML or Markdown, this function can be used to upload local image files to Imgur, e.g. set the package option opts_knit$set(upload.fun = imgur_upload), so the output document is completely self-contained, i.e. it does not need external image files any more, and it is ready to be published online.

Value

A character string of the link to the image; this string carries an attribute named XML which is a list converted from the response XML file; see Imgur API in the references.

Note

Please register your own Imgur application to get your client ID; you can certainly use mine, but this ID is in the public domain so everyone has access to all images associated to it.

Author(s)

Yihui Xie, adapted from the imguR package by Aaron Statham

References

A demo: https://yihui.org/knitr/demo/upload/

Examples

## Not run: 
f = tempfile(fileext = ".png")
png(f)
plot(rnorm(100), main = R.version.string)
dev.off()

res = imgur_upload(f)
res  # link to original URL of the image
attr(res, "XML")  # all information
if (interactive())
    browseURL(res)

# to use your own key
options(knitr.imgur.key = "your imgur key")

## End(Not run)

knitr documentation built on Nov. 2, 2023, 5:49 p.m.