我正在尝试使用magick
从一堆图像创建一个动画 gif。它工作得很好,但我想在创建 gif 之前为每个图像注释文本(基本上是文件名) - 但这不起作用。
我找不到错误的原因(如下)——不确定是管道符号、映射函数还是其他原因。
library(purrr)
library(magick)
#set working directory with a couple of png's
#This works:
image_read("image1.png") %>% image_annotate("Text")
#and this works too:
list.files(path = "", pattern = "*.png", full.names = T) %>%
map(image_read) %>%
image_join() %>%
image_animate(fps=1) %>%
image_write("animated.gif")
#but this doesn't:
list.files(path = "", pattern = "*.png", full.names = T) %>%
map(image_read) %>%
map(image_annotate("Text")) %>%
image_join() %>%
image_animate(fps=1) %>%
image_write("animated.gif")
我收到此错误:Error in inherits(image, "magick-image") :
argument "image" is missing, with no default
在我看来,错误可能出在嵌套地图上。
由于您已经在期间绘制了地图image_read
,没有必要再次这样做image_annotate
,
Edit所以我们需要应用这个函数image_annotate
映射返回的列表中的每个元素image_read
。尝试更换map(image_annotate("Text") %>%
with :
lapply(image_annotate("Text")) %>%
or
lapply(. %>% image_annotate("Text")) %>%
lapply() 参考 https://www.rdocumentation.org/packages/base/versions/3.4.1/topics/lapply
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)