R:动画包的新错误:convert.exe 不再在 Imagemagick 中

标签 r animation imagemagick-convert

从动画的 2.5 版开始,似乎仍然存在在 Windows 7 上调用 ImageMagick 实用程序 convert.exe 的路径的错误。这可以通过将转换选项添加到 ani.option 来解决。但是,现在新版本 7(.0.6.Q16) 不包含 covert.exe(动态和静态版本)。 ImageMagick 中 exe 文件的 DOS 列表给出

Directory of C:\Program Files\ImageMagick-7.0.6-Q16

11/Jun/17  12:10 PM           828,416 dcraw.exe
11/Jun/17  12:08 PM        33,351,680 ffmpeg.exe
11/Jun/17  12:08 PM           113,664 hp2xx.exe
11/Jun/17  12:14 PM        16,340,480 imdisplay.exe
11/Jun/17  12:14 PM        16,471,552 magick.exe
20/Jun/17  11:22 AM         1,202,385 unins000.exe
6 File(s)     68,308,177 bytes

Directory of C:\Program Files\ImageMagick-7.0.6-Q16\uninstall

11/Jun/17  12:07 PM           122,279 PathTool.exe
1 File(s)        122,279 bytes

Total Files Listed:
7 File(s)     68,430,456 bytes

因此,用于创建具有以下法线的动画 GIF 的 R 命令失败并显示错误
Executing: 
""C:\Program Files\ImageMagick-7.0.6-Q16\convert.exe" -loop 0 -delay 12 Rplot1.png Rplot2.png Rplot3.png
    Rplot4.png Rplot5.png Rplot6.png Rplot7.png Rplot8.png Rplot9.png Rplot10.png Rplot11.png Rplot12.png
    Rplot13.png Rplot14.png Rplot15.png Rplot16.png Rplot17.png Rplot18.png Rplot19.png Rplot20.png
    "Normals1_Ani.gif""
'"C:\Program Files\ImageMagick-7.0.6-Q16\convert.exe"' is not recognized as an internal or external command,
operable program or batch file.
an error occurred in the conversion... see Notes in ?im.convert
[1] FALSE

im.convert 帮助没有提到缺少 convert.exe 的可能性。

我运行的 R 命令是
 library(animation)
 donorm = function(k){
   require(ggplot2)
   Ns = matrix(0, 1000, k)
   X = matrix(0, 1000, k)
   for (i in 1:k){
     X[, i] = sort(rnorm(1000, mean = ifelse(i<11,0,2), sd = 0.5*ifelse(i<11,sqrt(i), sqrt(i -10))))
     Ns[, i] = dnorm(X[,i], mean = ifelse(i<11,0, 2), sd = 0.5*ifelse(i<11,sqrt(i), sqrt(i -10)))
   }
   mx = c(min(X), max(X))
   my = max(Ns)
   dat = data.frame(x = rep(0, 1000), y = rep(0, 1000))
   for (i in 1:k){
     dat$x = X[,i]; dat$y = Ns[,i]
     pl = ggplot2::ggplot(dat, aes(x = x, y= y)) + geom_line(color = i%%5 + 1, size = 1.5) + 
     coord_cartesian(xlim = mx, ylim = c(0, my)) +
     annotate("text", x = mx[1]+0.25, y = my[2]-0.25, label = 
                paste("mean = ", round(ifelse(i<11,0,2),1),"//st.dev = ", round(0.5*ifelse(i<11,sqrt(i), sqrt(i -10)), 1))) +
       theme_bw()
     print(pl)
   }
 }

## this is suggested solution for calling convert.exe but it fails on my system
# path_to_convert <- paste0(shortPathName("C:\\Program Files\\ImageMagick-7.0.6-Q16\\"), "convert.exe")

## this would work were the exe there
path_to_convert = "\"C:\\Program Files\\ImageMagick-7.0.6-Q16\\convert.exe\""

animation::ani.options(interval = 0.12, ani.width = 480, ani.height = 320, convert=path_to_convert)
animation::saveGIF(donorm(20), movie.name = paste0("Normals",1,"_Ani.gif"))

命令是正确的,预期的图像(用我的笔记本电脑制作,ImageMagick 嵌入 LyX - 不确定哪个版本的 ImageMagick 但 convert.exe 是版本 6)如图所示。 enter image description here

我无法安装 Imagemagick 版本 6,因为 website 上只存在版本 7 的二进制文件,change log 没有提到删除 convert.exe 实用程序。我不想安装 LyX。

有人可以提出解决方案吗?

更新解决方案

正如@fnw42 的回答中提到的,在 ImageMagick 第 7 版中

The "magick" command is the new primary command of the Shell API, replacing the old "convert" command.



所以要使用 saveGif 必须在 convert 命令选项中反射(reflect)这一变化。例如,在上面的代码中,需要将 convert.exe 替换为 magick.exe,如下所示
path_to_convert = "\"C:\\Program Files\\ImageMagick-7.0.6-Q16\\magick.exe\""

还可以将旧的 convert 实用程序称为“magick convert”。现在不推荐使用某些选项,并添加了一些新选项。检查 porting explanation 的详细信息。

我还发现旧的 Imagemagick 版本在 sourceforge 上可用。

最佳答案

在 Imagemagck 7 中,您必须将 convert (convert.exe) 替换为 magick (magick.exe,除非您从 Widows ImageMagick 安装程序安装旧组件。然后 convert.exe 将实际运行 IM 6。要运行 IM 7,请使用魔法。见http://imagemagick.org/script/porting.php#cli

抱歉,我不知道 R。

关于R:动画包的新错误:convert.exe 不再在 Imagemagick 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44643930/

相关文章:

r - 为什么 rbind() 和 do.call(rbind, ) 返回不同的结果?

c++ - Rcpp 中的逐元素矩阵乘法

android - setOffscreenPageLimit() 是如何通过保留更多离屏Fragment 来提高ViewPager 性能的?

powershell - Powershell 脚本中的参数

imagemagick - 使用 ImageMagick 在一个正方形中组合多个图像并调整其大小

r - 比较两个变量中的相应值

r - 如何为动物园对象(格子)的 xyplot 设置 ylim

android - Android OpenGL 中的平滑动画过渡逻辑

android - 具有自定义持续时间的 ActivityOptionsCompat.makeSceneTransitionAnimation

Imagemagick添加和阅读评论