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

feat(webshot): Round v{width,height} to nearest integer #70

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Suggests:
shiny
Encoding: UTF-8
Language: en-US
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# webshot2 (development version)

* `webshot()` now rounds `vwidth` and `vheight` to the nearest integer to match Chrome's expectations. If this behavior is somehow problematic, you can use `vwidth = I(my_width)` to avoid the conversion. (#70)

# webshot2 0.1.1

* `webshot()` now supports JPEG (`.jpg` or `.jpeg`) and WEBP (`.webp`) image formats. (@trafficonese #45)
Expand Down
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
as_rounded_int <- function(x) {
if (inherits(x, "AsIs")) x else round(x, digits = 0)
}

# =============================================================================
# System
# =============================================================================
Expand Down
9 changes: 5 additions & 4 deletions R/webshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ NULL
#' to the file name. For PDF output, it is just like printing the page to PDF
#' in a browser; \code{selector}, \code{cliprect}, \code{expand}, and
#' \code{zoom} will not be used for PDFs.
#' @param vwidth Viewport width. This is the width of the browser "window".
#' @param vheight Viewport height This is the height of the browser "window".
#' @param vwidth,vheight Viewport width and height. This is the width or height
#' of the virtual browser "window". Chrome expects integer values; numeric
#' values are rounded to the nearest integer.
#' @param selector One or more CSS selectors specifying a DOM element to set the
#' clipping rectangle to. The screenshot will contain these DOM elements. For
#' a given selector, if it has more than one match, all matching elements will
Expand Down Expand Up @@ -164,8 +165,8 @@ webshot <- function(
args_all <- list(
url = url,
file = file,
vwidth = vwidth,
vheight = vheight,
vwidth = as_rounded_int(vwidth), # Chrome requires integer viewport pxs
vheight = as_rounded_int(vheight),
selector = selector,
cliprect = cliprect,
expand = expand,
Expand Down
6 changes: 3 additions & 3 deletions man/webshot.Rd

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