0

I would like to learn how to create a simple GIF. I found this code :

dir.create("examples")
setwd("examples")

# example 1: simple animated countdown from 10 to "GO!".
png(file="example%02d.png", width=200, height=200)
for (i in c(10:1, "G0!")){
  plot.new()
  text(.5, .5, i, cex = 6)
}
dev.off()

which creates 11 png images. I would like to create a GIF file from these 11 eleven images, so I am using system("convert -delay 80 *.png example_1.gif"). But I get an error

> system("convert -delay 80 *.png example_1.gif")
  Invalid Parameter - 80
  Warning message:
  running command 'convert -delay 80 *.png example_1.gif' had status 4

I have also looked at Creating a Movie from a Series of Plots in R; but this does not work for me either.

P.S. I have already installed ImageMagick

Community
  • 1
  • 1
quant
  • 4,062
  • 5
  • 29
  • 70
  • Do you have ImageMagick installed and you can use it (meaning it's residing fine in your PATH)? – Roman Luštrik Apr 11 '17 at 15:55
  • These days you can use the animation or magick packages directly; but it should work the other way too. I just did it recently on one of my machines.... – Dirk Eddelbuettel Apr 11 '17 at 15:56
  • @RomanLuštrik to which PATH are you referring to ? the one that appears with `getwd()` ? – quant Apr 11 '17 at 16:02
  • System PATH which enables `system` call to access command line programs. – Roman Luštrik Apr 11 '17 at 17:07
  • 2
    You may need to provide the full path to Imagemagick convert. – fmw42 Apr 11 '17 at 18:56
  • @RomanLuštrik how can I do that ? – quant Apr 12 '17 at 07:54
  • @fmw42 i tfound this solution online `ani.options( convert = shQuote('C:/Program Files/ImageMagick-7.0.5-Q16/convert.exe') )`, but on my ImageMagick file there is no convert.exe ... – quant Apr 12 '17 at 07:55
  • Then you need to address this first. Convert may be "hiding" somewhere else? – Roman Luštrik Apr 12 '17 at 08:02
  • @RomanLuštrik i found the executable. so now i changed my code to `library(animation) ani.options( # convert = shQuote('C:/Program Files/ImageMagick-7.0.5-Q16/convert.exe') convert = shQuote('C:/Windows/System32/convert.exe') )` but i still get the same error when i run `system("convert -delay 80 *.png example_1.gif")` – quant Apr 12 '17 at 08:48
  • If you are on Windows. then there is a convert.exe as well as the convert.exe from Imagemagick. So you may need to rename the IM convert to something else, so that you get the correct convert. If you are not on Windows, then ignore this comment – fmw42 Apr 15 '17 at 18:16
  • From here: https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=29582 i found why i could not find the `convert.exe`. So now I run: `library(animation) ani.options( convert = shQuote('C:/Program Files/ImageMagick-7.0.5-Q16/convert.exe') )` but i still get the same error: `> system("convert -delay 80 *.png example_1.gif") Invalid Parameter - 80 Warning message: running command 'convert -delay 80 *.png example_1.gif' had status 4` – quant Apr 18 '17 at 13:42
  • @quant consider providing a summary what has bee provided here in the comments in the question so you may get your answer faster. – M-- Apr 25 '17 at 15:30
  • I think that you only fixed it for the package `animation` , but you are not using it. If you use `system()` you're still calling `convert.exe` in the `System32` folder. If you want to use `system()` you need to use the full path in `system()` (as mention by @fmw42) or rename convert.exe to something else (NOT the one in the `system32` folder. I haven't used the `animation` package before, but it looks like `saveGIF()` is the one you need and this will then use the convert you specified with `ani.options` . – ricoderks Apr 26 '17 at 11:06

1 Answers1

1

Try running system("convert /?") to see the source of your problem!!!

Converts a FAT volume to NTFS.

CONVERT volume /FS:NTFS [/V] [/CvtArea:filename] [/NoSecurity] [/X]


  volume      Specifies the drive letter (followed by a colon),
              mount point, or volume name.
  /FS:NTFS    Specifies that the volume will be converted to NTFS.
  /V          Specifies that Convert will be run in verbose mode.
  /CvtArea:filename
              Specifies a contiguous file in the root directory
              that will be the place holder for NTFS system files.
  /NoSecurity Specifies that the security settings on the converted
              files and directories allow access by all users.
  /X          Forces the volume to dismount first if necessary.
              All open handles to the volume will not be valid.

If you have version 7 of ImageMagick installed,then this line should solve the problem.

system("magick -delay 80 *.png example_1.gif")

enter image description here

Jeremy Voisey
  • 1,257
  • 9
  • 13