Search code examples
ranimationimagemagick-convert

R: new error with animation package: convert.exe no longer in Imagemagick


As of version 2.5 of animation, it seems that the bug with the path for calling the ImageMagick utility convert.exe on Windows 7 is still present. This can be fixed by adding the convert option to ani.option. However, now the new version 7(.0.6.Q16) doesn't contain covert.exe (both dynamic and static builds). The DOS list of exe files in ImageMagick gives

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

Therefore, the R commands for creating an animated GIF with normals below fail with the error

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

The im.convert help does not mention the possibility of missing convert.exe.

The R commands I ran are

 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"))

The commands are correct and the expected image (produced with my laptop with ImageMagick embedded in LyX -not sure which build of ImageMagick but convert.exe is version 6) is as shown.enter image description here

I cannot install Imagemagick version 6 because only the binaries for version 7 are present on the website, the change log does not mention removing the convert.exe utility. I would prefer not to install LyX.

Can someone suggest a solution?

UPDATE with solution

As mentioned in @fnw42's answer, in ImageMagick release 7

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

So to use saveGif one has to reflect this change in the convert command option. For example, in the code above one needs to replace convert.exe with magick.exe as in

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

One can also invoke the old convert utility as 'magick convert'. Some options are now deprecated and some new ones have been added. Check details on the porting explanation.

I also found that old Imagemagick versions are available on sourceforge.


Solution

  • In Imagemagck 7, you must replace convert (convert.exe) with magick (magick.exe, unless you install the legacy components from your Widows ImageMagick installer program. Then convert.exe will be actually running IM 6. To run IM 7, use magick. See http://imagemagick.org/script/porting.php#cli

    Sorry, I do not know R.