device {magick} | R Documentation |
Magick Graphics Device
Description
Graphics device that produces a Magick image. Can either be used like a regular
device for making plots, or alternatively via image_draw
to open a device
which draws onto an existing image using pixel coordinates. The latter is vectorized,
i.e. drawing operations are applied to each frame in the image.
Usage
image_graph(
width = 800,
height = 600,
bg = "white",
pointsize = 12,
res = 72,
clip = TRUE,
antialias = TRUE
)
image_draw(image, pointsize = 12, res = 72, antialias = TRUE, ...)
image_capture()
Arguments
width |
in pixels |
height |
in pixels |
bg |
background color |
pointsize |
size of fonts |
res |
resolution in pixels |
clip |
enable clipping in the device. Because clipping can slow things down a lot, you can disable it if you don't need it. |
antialias |
TRUE/FALSE: enables anti-aliasing for text and strokes |
image |
an existing image on which to start drawing |
... |
additional device parameters passed to plot.window such as
|
Details
The device is a relatively recent feature of the package. It should support all operations but there might still be small inaccuracies. Also it is a bit slower than some of the other devices, in particular for rendering text and clipping. Hopefully this can be optimized in the next version.
By default image_draw
sets all margins to 0 and uses graphics coordinates to
match image size in pixels (width x height) where (0,0)
is the top left corner.
Note that this means the y axis increases from top to bottom which is the opposite
of typical graphics coordinates. You can override all this by passing custom
xlim
, ylim
or mar
values to image_draw
.
The image_capture
function returns the current device as an image. This only
works if the current device is a magick device or supports dev.capture.
See Also
Other image:
_index_
,
analysis
,
animation
,
attributes()
,
color
,
composite
,
defines
,
edges
,
editing
,
effects()
,
fx
,
geometry
,
morphology
,
ocr
,
options()
,
painting
,
segmentation
,
transform()
,
video
Examples
# Regular image
frink <- image_read("https://jeroen.github.io/images/frink.png")
# Produce image using graphics device
fig <- image_graph(res = 96)
ggplot2::qplot(mpg, wt, data = mtcars, colour = cyl)
dev.off()
# Combine
out <- image_composite(fig, frink, offset = "+70+30")
print(out)
# Or paint over an existing image
img <- image_draw(frink)
rect(20, 20, 200, 100, border = "red", lty = "dashed", lwd = 5)
abline(h = 300, col = 'blue', lwd = '10', lty = "dotted")
text(10, 250, "Hoiven-Glaven", family = "monospace", cex = 4, srt = 90)
palette(rainbow(11, end = 0.9))
symbols(rep(200, 11), seq(0, 400, 40), circles = runif(11, 5, 35),
bg = 1:11, inches = FALSE, add = TRUE)
dev.off()
print(img)
# Vectorized example with custom coordinates
earth <- image_read("https://jeroen.github.io/images/earth.gif")
img <- image_draw(earth, xlim = c(0,1), ylim = c(0,1))
rect(.1, .1, .9, .9, border = "red", lty = "dashed", lwd = 5)
text(.5, .9, "Our planet", cex = 3, col = "white")
dev.off()
print(img)