With much of the work done by the creators of the magick
package, I was able to tidy up some of the process of creating a transition animation. Instead of needing a few lines of code and multiple function calls to do this, my function allows for a single function call in order to create an animation transition by taking as arguments the URL or path to the baseline image for the start of the transition, the URL or path to the image to transition to at end, and the number of frames during the transition. The source code for my function, TranImage
, is displayed below along with two examples of its use.
Also, I noticed Github does not want to display my HTML file I created since it says it is too large, so here is a link to the HTML file published using RPubs.
library(magick)
TranImage <- function(image1, image2, nframes = 10) {
# A function for creating a transition graphic
#
# Args:
# image1: URL or path to baseline image for start of transition
# image2: URL or path to image to transition to at end
# nframes: number of frames during transition
#
# Returns:
# transition animation of specified images
newlogo <- image_scale(image_read(image2), "x150")
oldlogo <- image_scale(image_read(image1), "x150")
frames <- image_morph(c(oldlogo, newlogo), frames = nframes)
image_animate(frames)
}
TranImage(image1 = paste0("https://twin-cities.umn.edu/sites/twin-cities.umn.",
"edu/files/styles/panopoly_image_original/public/19",
"86-goldy.gif?itok=T0fgrb4Y"),
image2 = paste0("https://twin-cities.umn.edu/sites/twin-cities.umn.",
"edu/files/styles/panopoly_image_original/public/19",
"85-goldy.gif?itok=-r6k5Nve"), nframes = 20)
TranImage(image1 = "https://www.r-project.org/logo/Rlogo.png",
image2 = "https://developer.r-project.org/Logo/Rlogo-3.png")