Tools to Work with the 'Splash' JavaScript Rendering Service in R
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

74 wiersze
2.9 KiB

7 lat temu
#' Return a image (in JPEG format) of the javascript-rendered page.
#'
#' @md
#' @param quality JPEG quality parameter in range from 0 to 100. Default is quality=75.
#' @inheritParams render_html
#' @inheritParams render_png
7 lat temu
#' @family splash_renderers
7 lat temu
#' @return a [magick] image object
7 lat temu
#' @references [Splash docs](http://splash.readthedocs.io/en/stable/index.html)
7 lat temu
#' @export
7 lat temu
render_jpeg <- render_jpg <- function(
splash_obj = splash_local, url, base_url=NULL, quality=75, width, height,
timeout=30, resource_timeout, wait=0, render_all=TRUE,
7 lat temu
proxy, js, js_src, filters, allowed_domains, allowed_content_types,
forbidden_content_types, viewport="full", images, headers, body,
http_method, save_args, load_args, http2 = FALSE,
engine = c("webkit", "chromium")) {
7 lat temu
wait <- check_wait(wait)
engine <- match.arg(engine[1], c("webkit", "chromium"))
http2 <- if (engine == "chromium") NULL else as.integer(as.logical(http2[1]))
viewport <- if (engine == "chromium") NULL else jsonlite::unbox(viewport[1])
render_all <- if (engine == "chromium") NULL else as.integer(render_all[1])
wait <- if (is.null(render_all)) 0.5 else if (render_all & wait == 0) 0.5 else wait
list(
url = url,
timeout = timeout,
wait = wait,
viewport = viewport,
render_all = render_all,
quality = quality,
http2 = http2,
engine = engine
) -> params
7 lat temu
if (!missing(width)) params$width <- width
if (!missing(height)) params$height <- height
if (!missing(base_url)) params$base_url <- jsonlite::unbox(base_url)
7 lat temu
if (!missing(resource_timeout)) params$resource_timeout <- resource_timeout
if (!missing(proxy)) params$proxy <- jsonlite::unbox(proxy)
if (!missing(js)) params$js <- jsonlite::unbox(js)
if (!missing(js_src)) params$js_src <- jsonlite::unbox(js_src)
if (!missing(filters)) params$filters <- jsonlite::unbox(filters)
if (!missing(allowed_domains)) params$allowed_domains <- jsonlite::unbox(allowed_domains)
if (!missing(allowed_content_types)) params$allowed_content_types <- jsonlite::unbox(allowed_content_types)
if (!missing(forbidden_content_types)) params$forbidden_content_types <- jsonlite::unbox(forbidden_content_types)
if (!missing(images)) params$images <- as.numeric(images)
7 lat temu
if (!missing(headers)) params$headers <- headers
if (!missing(body)) params$body <- jsonlite::unbox(body)
if (!missing(http_method)) params$http_method <- jsonlite::unbox(http_method)
if (!missing(save_args)) params$save_args <- jsonlite::unbox(save_args)
if (!missing(load_args)) params$load_args <- jsonlite::unbox(load_args)
7 lat temu
if (is.null(splash_obj$user)) {
res <- httr::GET(splash_url(splash_obj), path="render.jpeg", encode="json", query=params)
} else {
res <- httr::GET(
splash_url(splash_obj), path="render.jpeg", encode="json", query=params,
httr::authenticate(splash_obj$user, splash_obj$pass)
)
}
7 lat temu
check_or_report_status(res)
7 lat temu
magick::image_read(httr::content(res, as="raw"))
7 lat temu
}