Distorts a magick-image using a four-point perspective transformation,
giving the "floating HUD panel" effect.
Usage
warp_hud(img, corners = list(), keep_size = TRUE, ...)Arguments
- img
A
magick-imageobject, typically produced byrender_hud().- corners
A named list specifying how far each corner of the image should move from its natural position. Each element is a numeric vector of length 2:
c(dx, dy), where positive values move right/down. Names must be"tl"(top-left),"tr"(top-right),"bl"(bottom-left), and"br"(bottom-right). Any corner omitted defaults toc(0, 0)(no movement).Example: tilt the panel so the left edge rises and the right edge drops:
- keep_size
If
TRUE(default), the output image is cropped/padded back to the original pixel dimensions. IfFALSE, ImageMagick may expand the canvas to contain the warped result.- ...
Currently unused.
Examples
if (FALSE) { # \dontrun{
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
img <- render_hud(p, width = 500, height = 350)
# Tilt the top edge backward (raise both top corners)
warped <- warp_hud(img, corners = list(tl = c(20, -15), tr = c(-20, -15)))
magick::image_browse(warped)
} # }
