Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow JPG / JPEG, add verbose argument #45

Merged
merged 6 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions R/webshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ NULL
#' device (but using zoom will not report that there is a HiDPI device).
#' @param useragent The User-Agent header used to request the URL.
#' @param max_concurrent (Currently not implemented)
#' @param verbose Show / Hide console messages
gadenbuie marked this conversation as resolved.
Show resolved Hide resolved
#' @template webshot-return
#'
#' @examples
Expand Down Expand Up @@ -117,7 +118,8 @@ webshot <- function(
delay = 0.2,
zoom = 1,
useragent = NULL,
max_concurrent = getOption("webshot.concurrent", default = 6)
max_concurrent = getOption("webshot.concurrent", default = 6),
verbose = TRUE
gadenbuie marked this conversation as resolved.
Show resolved Hide resolved
) {

if (length(url) == 0) {
Expand Down Expand Up @@ -196,7 +198,8 @@ webshot <- function(
function(args) {
new_session_screenshot(cm,
args$url, args$file, args$vwidth, args$vheight, args$selector,
args$cliprect, args$expand, args$delay, args$zoom, args$useragent
args$cliprect, args$expand, args$delay, args$zoom, args$useragent,
verbose
gadenbuie marked this conversation as resolved.
Show resolved Hide resolved
)
}
)
Expand All @@ -219,12 +222,14 @@ new_session_screenshot <- function(
expand,
delay,
zoom,
useragent
useragent,
verbose
gadenbuie marked this conversation as resolved.
Show resolved Hide resolved
) {

filetype <- tolower(tools::file_ext(file))
if (filetype != "png" && filetype != "pdf") {
stop("File extension must be 'png' or 'pdf'")
filetypes <- c("png","pdf","jpg","jpeg")
if (!filetype %in% filetypes) {
stop("File extension must be one of: ", paste(filetypes, collapse = ", "))
}

if (is.null(selector)) {
Expand Down Expand Up @@ -275,7 +280,7 @@ new_session_screenshot <- function(
}
})$
then(function(value) {
if (filetype == "png") {
if (filetype == "png" || filetype == "jpg" || filetype == "jpeg") {
gadenbuie marked this conversation as resolved.
Show resolved Hide resolved
s$screenshot(
filename = file, selector = selector, cliprect = cliprect,
expand = expand, scale = zoom,
Expand All @@ -287,7 +292,9 @@ new_session_screenshot <- function(
}
})$
then(function(value) {
message(url, " screenshot completed")
if (verbose) {
message(url, " screenshot completed")
}
gadenbuie marked this conversation as resolved.
Show resolved Hide resolved
normalizePath(value)
})$
finally(function() {
Expand Down
5 changes: 4 additions & 1 deletion man/webshot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.