| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/image.R |
| 3 |
\name{upload_imgur} |
| 4 |
\alias{upload_imgur} |
| 5 |
\title{Upload an image to imgur.com} |
| 6 |
\usage{ |
| 7 |
upload_imgur( |
| 8 |
file, |
| 9 |
key = env_option("xfun.upload_imgur.key"), |
| 10 |
use_curl = loadable("curl"), |
| 11 |
include_xml = FALSE |
| 12 |
) |
| 13 |
} |
| 14 |
\arguments{ |
| 15 |
\item{file}{Path to the image file to be uploaded.} |
| 16 |
|
| 17 |
\item{key}{Client ID for Imgur. It can be set via either the global option |
| 18 |
\code{xfun.upload_imgur.key} or the environment variable |
| 19 |
\code{R_XFUN_UPLOAD_IMGUR_KEY} (see \code{\link[=env_option]{env_option()}}). If neither is set, this |
| 20 |
uses a client ID registered by Yihui Xie.} |
| 21 |
|
| 22 |
\item{use_curl}{Whether to use the R package \pkg{curl} to upload the image. |
| 23 |
If \code{FALSE}, the system command \code{curl} will be used.} |
| 24 |
|
| 25 |
\item{include_xml}{Whether to include the XML response in the returned value.} |
| 26 |
} |
| 27 |
\value{ |
| 28 |
A character string of the link to the image. If \code{include_xml = TRUE}, |
| 29 |
this string carries an attribute named \code{XML}, which is the XML response |
| 30 |
from Imgur (it will be parsed by \pkg{xml2} if available). See Imgur API in |
| 31 |
the references. |
| 32 |
} |
| 33 |
\description{ |
| 34 |
This function uses the \pkg{curl} package or the system command \code{curl} |
| 35 |
(whichever is available) to upload a image to \url{https://imgur.com}. |
| 36 |
} |
| 37 |
\details{ |
| 38 |
One application is to upload local image files to Imgur when knitting a |
| 39 |
document with \pkg{knitr}: you can set the \verb{knitr::opts_knit$set(upload.fun = xfun::upload_imgur}, so the output document does not need local image files |
| 40 |
any more, and it is ready to be published online. |
| 41 |
} |
| 42 |
\note{ |
| 43 |
Please register your own Imgur application to get your client ID. You |
| 44 |
can certainly use mine, but this ID is in the public domain and it might |
| 45 |
reach Imgur's rate limit if too many people are using it in the same time |
| 46 |
period or someone is trying to upload too many images at once. |
| 47 |
} |
| 48 |
\examples{ |
| 49 |
\dontrun{ |
| 50 |
f = tempfile(fileext = ".png") |
| 51 |
png(f) |
| 52 |
plot(rnorm(100), main = R.version.string) |
| 53 |
dev.off() |
| 54 |
|
| 55 |
res = imgur_upload(f, include_xml = TRUE) |
| 56 |
res # link to original URL of the image |
| 57 |
xfun::attr2(res, "XML") # all information |
| 58 |
if (interactive()) |
| 59 |
browseURL(res) |
| 60 |
|
| 61 |
# to use your own key |
| 62 |
options(xfun.upload_imgur.key = "your imgur key") |
| 63 |
} |
| 64 |
} |
| 65 |
\references{ |
| 66 |
A demo: \url{https://yihui.org/knitr/demo/upload/} |
| 67 |
} |
| 68 |
\author{ |
| 69 |
Yihui Xie, adapted from the \pkg{imguR} package by Aaron Statham |
| 70 |
} |