Learn R Programming

magick (version 0.1)

editing: Image Editing

Description

Read, write and join or combine images. All image functions are vectorized, meaning they operate either on a single frame or a series of frames (e.g. a collage, video, or animation). The Magick++ documentation explains meaning of each function and parameter.

Usage

image_read(path)
image_write(image, path = NULL, format = NULL)
image_display(image, animate = TRUE)
image_browse(image, browser = getOption("browser"))
image_append(image, stack = FALSE)
image_average(image)
image_coalesce(image)
image_flatten(image)
image_fft(image)
image_map(image, map, dither = FALSE)
image_montage(image)
image_morph(image, frames)
image_mosaic(image)
image_join(...)
image_info(image)
image_animate(image, fps = 10, loop = 0, dispose = c("background", "previous", "none"))

Arguments

path
file path, URL, or raw vector with image data
image
object returned by image_read
format
output format such as png, jpeg, gif or pdf.
animate
support animations in the X11 display
browser
argument passed to browseURL
stack
place images top-to-bottom (TRUE) or left-to-right (FALSE)
map
reference image to map colors from
dither
set TRUE to enable dithering
frames
number of frames to use in output animation
...
images or lists of images to be combined into a image
fps
frames per second
loop
how many times to repeat the animation. Default is infinite.
dispose
frame disposal method. See documentation

Details

Besides these functions also R-base functions such as c(), [, as.list(), rev, length, and print can be used to work with image frames. See transformations for vectorized image manipulation functions such as cutting and applying effects.

Some configurations of ImageMagick++ support reading SVG files but the rendering is not always very pleasing. Better results can be obtained by first rendering svg to a png using the rsvg package.

References

Magick++ Image STL: https://www.imagemagick.org/Magick++/STL.html

See Also

Other image: transformations

Examples

Run this code
# Download image from the web
frink <- image_read("https://jeroenooms.github.io/images/frink.png")
frink2 <- image_crop(frink)
image_write(frink2, "output.png")
# Create thumbnails from GIF
banana <- image_read(system.file("banana.gif", package = "magick"))
length(banana)
image_average(banana)
image_flatten(banana)
image_append(banana)
image_append(banana, stack = TRUE)

# Append images together
image_append(image_scale(c(image_append(banana[c(1,3)], stack = TRUE), frink)))
# Combine with another image
logo <- image_read(system.file("Rlogo.png", package = "magick"))
oldlogo <- image_read(system.file("Rlogo-old.png", package = "magick"))

# Create morphing animation
both <- image_scale(c(oldlogo, logo), "400")
image_average(image_crop(both))
image_animate(image_morph(both, 10))
# Basic compositions
image_composite(banana, image_scale(logo, "300"))

# Break down and combine frames
front <- image_scale(banana, "300")
background <- image_scale(logo, "400")
frames <- lapply(as.list(front), function(x) image_flatten(c(background, x)))
image_animate(image_join(frames))

Run the code above in your browser using DataLab