【问题标题】:R: new error with animation package: convert.exe no longer in ImagemagickR:动画包的新错误:Imagemagick 中不再有 convert.exe
【发布时间】:2017-11-22 11:00:51
【问题描述】:

截至动画的 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"))

命令正确,预期的图像(使用我的笔记本电脑生成,其中嵌入了 LyX 的 ImageMagick - 不确定 ImageMagick 的哪个版本,但 convert.exe 是版本 6)如图所示。

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

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

更新解决方案

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

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

所以要使用saveGif,必须在转换命令选项中反映这一变化。例如,在上面的代码中,需要将convert.exe 替换为magick.exe,如

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

也可以调用旧的转换实用程序作为“魔术转换”。现在不推荐使用某些选项,并添加了一些新选项。查看porting explanation 的详细信息。

我还发现 sourceforge 上提供了旧的 Imagemagick 版本。

【问题讨论】:

  • 我们已经注意到这个问题,并将尝试在下一版本的动画包中使用magick。感谢您的耐心等待!
  • @Yihui 当然,感谢您的辛勤工作!希望这个答案可以帮助您找到最佳解决方案。

标签: r animation imagemagick-convert


【解决方案1】:

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

对不起,我不知道R。

【讨论】:

  • 这就是答案。谢谢。我在 IM 网站上寻找解释,但没有看到这个文档。
  • @fmw42 只是为了检查一下-替换是什么意思?重命名magick.exe,或者安装文件夹哪里可以找到convert.exe?
  • 我不知道 Ruby 或 R,所以我不知道它是如何调用 ImageMagick 命令的。但是您说您使用的是 IM 7 并且找不到转换。在 IM 7 中,没有转换。它改为magick,因此命令行ImageMagick 7中的命令以magick开头而不是转换。在 Windows 中,您可能需要调用 magick.exe。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-20
  • 2015-01-12
  • 1970-01-01
  • 2022-06-17
相关资源
最近更新 更多