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

时间:2017-06-20 04:37:18

标签: r animation imagemagick-convert

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

  

“magick”命令是Shell API的新主命令,取代了旧的“convert”命令。

因此,要使用saveGif,必须在convert命令选项中反映此更改。例如,在上面的代码中,需要将convert.exe替换为magick.exe,如

path_to_convert = "\"C:\\Program Files\\ImageMagick-7.0.6-Q16\\magick.exe\""

也可以将旧的转换实用程序作为'magick convert'调用。现在已弃用某些选项,并添加了一些新选项。查看porting explanation的详细信息。

我还发现sourceforge上有旧的Imagemagick版本。

1 个答案:

答案 0 :(得分:2)

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

对不起,我不知道R。