动画.gif连续重复。我想在每个循环后添加x秒的延迟。是否有用于目的的参数?
使用.gif的各个帧的索引来构建一个带有“暂停”的新.gif。您可以通过重复相同的框架来创建暂停的效果。 使用
image_animate()
复制“暂停”帧n次数以控制暂停长度的次数。
从您的示例中,如果您想在GIF的最后框架上徘徊,您会想要这样的东西:rep()
对于其他有兴趣将.GIF作为图像库的人,您可能需要查看
gif <- function(name, imgDir, format, fps, delete) {
require(magick)
require(gtools)
imgs <- mixedsort(list.files(path = imgDir, pattern = paste("*.", format, sep = "")))
image <- image_read(paste(imgDir, "/", imgs, sep = ""))
animation <- image_animate(image, fps = fps)
#Pause on the last frame for 1 second
#Use c() to combine image frames from one or more magick gif objects
gif_with_pause<-c(animation, rep(animation[length(animation)],10))
image_write(gif_with_pause, paste(name, ".gif", sep = ""))
}
gif("animation_with_pause", "tmp", "png", 10, TRUE)
magick::image_morph()
library(magick)
library(dplyr)
#read in some images
i1<-image_read("https://upload.wikimedia.org/wikipedia/commons/thumb/f/fd/Ghostscript_Tiger.svg/512px-Ghostscript_Tiger.svg.png")
i2<-image_read("https://jeroen.github.io/images/frink.png")
#make a gif image
initial_gif<-image_resize(c(i1, i2), '200x200!') %>%
image_background('white') %>%
image_morph( frames = 10) %>%
image_animate(optimize = TRUE, fps = 10)
#make another gif with the last image moving to the first image
last_img_to_1st_gif<-image_resize(c(i2,i1), '200x200!') %>%
image_background('white') %>%
image_morph( frames = 10) %>%
image_animate(optimize = TRUE, fps = 10)
#use rep() to linger on the first image, cycle the gif, linger on the second image,
#then show a transition back to the first image.
new_gif<-c(rep(initial_gif[1],10),
initial_gif,
rep(initial_gif[length(initial_gif)],10),
last_img_to_1st_gif)
结果是结果: