saveGIF: Convert images to a single animation file (typically GIF)...

Description Usage Arguments Details Value Note Author(s) References See Also

View source: R/saveGIF.R

Description

This function opens a graphical device (specified in ani.options('ani.dev')) first to generate a sequence of images based on expr, then makes use of the command convert in ‘ImageMagick’ to convert these images to a single animated movie (as a GIF or MPG file). An alternative software package is GraphicsMagick (use convert = 'gm convert'), which is smaller than ImageMagick.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
saveGIF(
  expr,
  movie.name = "animation.gif",
  img.name = "Rplot",
  convert = "magick",
  cmd.fun,
  clean = TRUE,
  extra.opts = "",
  ...
)

saveMovie(
  expr,
  movie.name = "animation.gif",
  img.name = "Rplot",
  convert = "magick",
  cmd.fun,
  clean = TRUE,
  extra.opts = "",
  ...
)

Arguments

expr

an expression to generate animations; use either the animation functions (e.g. brownian.motion()) in this package or a custom expression (e.g. for(i in 1:10) plot(runif(10), ylim = 0:1)).

movie.name

file name of the movie (with the extension)

img.name

file name of the sequence of images (‘pure’ name; without any format or extension)

convert

the command to convert images (default to be convert (i.e. use ImageMagick), but might be imconvert under some Windows platforms); can be gm convert in order to use GraphicsMagick; see the 'Note' section for details

cmd.fun

a function to invoke the OS command; by default system

clean

whether to delete the individual image frames

extra.opts

additional options passed to im.convert

...

other arguments passed to ani.options, e.g. ani.height and ani.width, ...

Details

This function calls im.convert (or gm.convert, depending on the argument convert) to convert images to a single animation.

The advantage of this function is that it can create a single movie file, however, there are two problems too: (1) we need a special (free) software ImageMagick or GraphicsMagick; (2) the speed of the animation will be beyond our control, as the interval option is fixed. Other approaches in this package may have greater flexibilities, e.g. the HTML approach (see saveHTML).

See ani.options for the options that may affect the output, e.g. the graphics device (including the height/width specifications), the file extension of image frames, and the time interval between image frames, etc. Note that ani.options('interval') can be a numeric vector!

Value

The command for the conversion (see im.convert).

Note

See im.convert for details on the configuration of ImageMagick (typically for Windows users) or GraphicsMagick.

It is recommended to use ani.pause() to pause between animation frames in expr, because this function will only pause when called in a non-interactive graphics device, which can save a lot of time. See the demo 'Xmas2' for example (demo('Xmas2', package = 'animation')).

saveGIF has an alias saveMovie (i.e. they are identical); the latter name is for compatibility to older versions of this package (< 2.0-2). It is recommended to use saveGIF to avoid confusions between saveMovie and saveVideo.

Author(s)

Yihui Xie

References

Examples at https://yihui.org/animation/example/savegif/

ImageMagick: http://www.imagemagick.org/script/convert.php;

GraphicsMagick: http://www.graphicsmagick.org

See Also

Other utilities: im.convert(), saveHTML(), saveLatex(), saveSWF(), saveVideo()


animation documentation built on Oct. 7, 2021, 9:18 a.m.