我在目录中有一堆png文件,我想通过R将它们转换为gif(动画)文件。你能建议怎么做吗?
Here is some dummy code you can use:
First use the magick
package for the GIF Use the magrittr
package or the dplyr
package for the %>%
library(magick)
library(magrittr)
Then list files in the directory, and combine into gif fps is frames per second
list.files(path='/$PATH/', pattern = '*.png', full.names = TRUE) %>%
image_read() %>% # reads each path file
image_join() %>% # joins image
image_animate(fps=4) %>% # animates, can opt for number of loops
image_write("FileName.gif") # write to current dir
A solution with the gifski
package:
library(gifski)
png_files <- list.files("path/to/your/pngs/", pattern = ".*png$", full.names = TRUE)
gifski(png_files, gif_file = "animation.gif", width = 800, height = 600, delay = 1)
The advantage of gifski
is that the number of colors in the GIF is not limited to 256.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.