使用R动画库和Imagemagick保存gif视频时出错

5
我正在尝试使用Windows 7创建一个简单的.gif视频。我安装了ImageMagick,它似乎可以正常运行。以下是我尝试运行的代码及其对应的错误消息。当我运行代码时,ImageMagik程序会打开,并且看起来绘制了第一次运行的数据(请参见下面的图像)。我怀疑问题在于Windows和Unix命令之间的差异?也许我需要添加更多内容到ani.options中?非常感谢任何帮助或建议。谢谢。

添加所需的库

library(animation)

确保convert位于数据保存的位置

ani.options(convert = 'C:/Program Files/ImageMagick-6.8.9-Q16/convert.exe')   ani.options(“convert”)#检查是否支持简写符号

[1]“C:/Program Files/ImageMagick-6.8.9-Q16/convert.exe”

创建一个图形的.gif视频

saveGIF({   +为(i in 1:10)plot(runif(10),ylim = 0:1)   +})

执行: “C:/Program Files/ImageMagick-6.8.9-Q16/convert.exe” -loop 0 -delay 100     Rplot1.png Rplot2.png Rplot3.png Rplot4.png Rplot5.png Rplot6.png     Rplot7.png Rplot8.png Rplot9.png Rplot10.png“animation.gif” 'C:/Program' 不是内部或外部命令,也不是可运行的程序或批处理文件。 输出为:animation.gif [1] TRUE 警告信息: 1:运行命令'C:\Windows\system32\cmd.exe /c “C:/Program Files/ImageMagick-6.8.9-Q16/convert.exe” -loop 0 -delay 100 Rplot1.png Rplot2.png Rplot3.png Rplot4.png Rplot5.png Rplot6.png Rplot7.png Rplot8.png Rplot9.png Rplot10.png“animation.gif”'状态为1 2:在cmd.fun(convert)中:  '"C:/Program Files/ImageMagick-6.8.9-Q16/convert.exe" -loop 0 -delay 100 Rplot1.png Rplot2.png Rplot3.png Rplot4.png Rplot5.png Rplot6.png Rplot7.png Rplot8.png Rplot9.png Rplot10.png“animation.gif”'执行失败,错误代码为1

imdisplay


3
你能测试一下开发版本吗? install.packages('animation', repos = 'http://rforge.net', type = 'source') - Yihui Xie
2个回答

2

我遇到了同样的问题。使用较短的文件路径解决了错误。

 path.to.convert <- paste0(shortPathName(
                    "C:\\Program Files\\ImageMagick-6.9.0-Q16\\"), "convert.exe")
 ani.options(convert=path.to.convert)

顺便提一下,这是帮助我的方法。如果有人能确认这是他们系统上的问题,请在这里评论,因为了解这是否是实际问题而不仅仅是我系统的特殊情况会很有帮助。 - coffeinjunky
2
错误信息清楚地显示问题在路径中的空格... 'C:/Program' 未被识别。 - Mark Setchell
@MarkSetchell 是的,程序就是这个空间,有没有比使用这个答案更永久的解决方法? - Herman Toothrot

2

我也遇到了同样的问题。简短路径技巧是解决方法!但是,在Image Magick 7.x版本中,不存在"convert.exe"。下面的方法可以解决问题:

ani.options(convert=shortPathName("C:\\Program Files\\ImageMagick\\magick.exe"))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接