# 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