5

I just spent an infuriating day trying to make a gif out of a series of jpg files in R. I installed ImageMagick to run the following code:

system("convert -delay 40 *.png example_4.gif")

but I get the following error message:

Warning message:
running command 'convert -delay 40 *.png example_4.gif' had status 4

which looks like a path error. Now I've looked for convert in the Imagemagick download and can't see it anywhere. Does anyone know where it is?

Alternately, is there another easier method of making a gif from a series of jpegs in R that isn't ridiculously long?

Thanks

fmw42
  • 46,825
  • 10
  • 62
  • 80
unknown
  • 853
  • 1
  • 10
  • 23
  • 3
    Try replacing `convert` with `magick` if using v7+ - especially if on **Windows** and you didn't select *"Install legacy option"* when installing **ImageMagick**. – Mark Setchell Sep 05 '17 at 16:19
  • I've just tried that and it gives a different error message: Warning message: running command 'magick -delay 40 *.png example_4.gif' had status 127 – unknown Sep 05 '17 at 16:23
  • I've just tried to get the legacy files option on install, but it doesn't give me the option to do that – unknown Sep 05 '17 at 16:25
  • 1
    I remember having this issue on windows. Unfortunately i cannot find my code now :(. I think solution was to specify full path to covert program – ilya Sep 05 '17 at 16:25
  • 1
    How about `magick convert`? – zindarod Sep 05 '17 at 16:25
  • 1
    It would help if you told us what OS you are using and how you installed **ImageMagick**... – Mark Setchell Sep 05 '17 at 16:26
  • @Zindarod that gives the same 127 error as before – unknown Sep 05 '17 at 16:26
  • @MarkSetchell using windows 7 and installed this version: ImageMagick-7.0.7-0-Q16-x64-static. Using R in Rstudio – unknown Sep 05 '17 at 16:27
  • 1
    So, look in the directory where you installed Imagemagick and find the name of the full path to the program `magick.exe` and use that full path in your `system()` command. – Mark Setchell Sep 05 '17 at 16:28
  • just tried that and unfortunately no luck. Same 127 error. – unknown Sep 05 '17 at 16:34
  • Thanks all for the helpful comments, lots of suggestions so I'll have a go and let you know what works – unknown Sep 05 '17 at 16:45

1 Answers1

10

Three options:

  1. Consider using the magick R package instead of using system().
  2. Change your script from convert ... to magick convert ....
  3. Re-install imagemagick, and enable the "Install legacy utilities (e.g. convert)" option.

    enter image description here

This change has been around since 7.0.1 (now up to 7.0.7), and is discussed in their porting guide, specifically in the section entitled "Command Changes".

Philosophically, I prefer to not install the legacy utilities, mostly because it can cause some confusion with command names. For instance, the non-ImageMagick convert.exe in windows tries to convert a filesystem ... probably not what you want to accidentally trigger (there is a very low chance that you could get the arguments right to actually make a change, but it's still not 0). The order of directories in your PATH will dictate which you are calling.

EDITs:

  1. From comments, it seems like the difference between "static" and "dll" installers might disable the option to install legacy utilities such as convert.exe. So you can either switch to the "dll" to get the legacy option, or you are restricted to options 1 (magick R package) and 2 ("magick convert ...").

  2. From further comments (thanks to fmw42 and MarkSetchell), it is clear that the old convert.exe and the current legacy mode of magick.exe convert are not the same as the currently recommended magick.exe (without "convert"); the first two are legacy and compatibility modes, but they do not accept all arguments currently supported by magick-alone. So the use of "convert" anywhere in the command should indicate use of v6, not the current v7. This answer is then merely a patch for continued use of the v6 mechanisms; one could argue a better solution would be to use magick.exe's v7 interface, completely removing the "convert" legacy mode.

r2evans
  • 141,215
  • 6
  • 77
  • 149
  • is it possible to make a gif using the magick package? If so, what command would you use? Just looking at the documentation and haven't found it yet – unknown Sep 05 '17 at 16:34
  • interestingly I actually get a different 'select additional tasks' box that only gives me the first 4 and the last option (so not the legacy option) – unknown Sep 05 '17 at 16:37
  • 1
    The [`magick` vignette](https://cran.r-project.org/web/packages/magick/vignettes/intro.html) is fairly complete, so I imagine it's possible. Since I don't create animated gifs like you are trying, I will take a cue from the "Animation" section that it should not be hard to do. – r2evans Sep 05 '17 at 16:38
  • ok I've downloaded the dll installer and it works if you change the script to magick convert! Thanks! – unknown Sep 05 '17 at 16:49
  • 2
    Magick, magick convert and convert are all different. The proper command in IM 7 is magick. The others point to legacy IM 6 methods. You should either find the path to magick and preface it with the path or put the path into your Environment PATH variable, so that you are properly using IM 7 (unless you want to use legacy IM 6 code). – fmw42 Sep 05 '17 at 17:12
  • There is no indication that `magick convert` and `convert` will use different IM code. The porting guide suggests that these utilies (often symlinks) are identical in effect. There is no doubt that `magick` is the preferred command going forward. What indication do you have that these two commands will produce different results? – r2evans Sep 05 '17 at 17:17
  • 1
    @r2evans `magick ...` and `magick convert ...` definitely **do** behave differently. Try `magick -size 100x100 xc:black -resize "%[fx:w*2]" a.jpg` to double the width of the image and it will be parsed and executed fine, but replace `magick` with either `convert` or `magick convert` and it will fail because the latter two implement v6 behaviour. – Mark Setchell Sep 05 '17 at 20:48
  • fmw42 and MarkSetchell, thanks, I stand corrected, thank you! (In this case, it isn't so much *"learn something new"* as *"unlearn something incorrect"*, but one of the two happens every day.) As salient as this point is, it doesn't necessarily change my answer: if you knowingly want the v6 behavior, then this is how you get it. If you want v7 behavior, you need to optionally translate from v6 to v7. – r2evans Sep 05 '17 at 21:23