animation (version 2.4.1)

im.convert: A wrapper for the `convert' utility of ImageMagick or GraphicsMagick

Description

The main purpose of these two functions is to create GIF animations.

Usage

im.convert(files, output = "animation.gif", convert = c("convert", "gm convert"), cmd.fun = if (.Platform$OS.type == "windows") shell else system, extra.opts = "", clean = FALSE)
gm.convert(..., convert = "gm convert")

Arguments

files
either a character vector of file names, or a single string containing wildcards (e.g. ‘Rplot*.png’)
output
the file name of the output (with proper extensions, e.g. gif)
convert
the convert command; it must be either 'convert' or 'gm convert'; and it can be pre-specified as an option in ani.options('convert'), e.g. (Windows users) ani.options(convert = 'c:/program files/imagemagick/convert.exe'), or (Mac users) ani.options(convert = '/opt/local/bin/convert'); see the Note section for more details
cmd.fun
a function to invoke the OS command; by default system
extra.opts
additional options to be passed to convert (or gm convert)
clean
logical: delete the input files or not
...
arguments to be passed to im.convert

Value

The command for the conversion.If ani.options('autobrowse') == TRUE, this function will also try to open the output automatically.

Details

The function im.convert simply wraps the arguments of the convert utility of ImageMagick to make it easier to call ImageMagick in R;

The function gm.convert is a wrapper for the command gm convert of GraphicsMagick.

References

ImageMagick: http://www.imagemagick.org/script/convert.php GraphicsMagick: http://www.graphicsmagick.org

See Also

Other utilities: saveGIF, saveHTML, saveLatex, saveSWF, saveVideo

Examples

Run this code
## generate some images
owd = setwd(tempdir())
oopt = ani.options(interval = 0.05, nmax = 20)
png("bm%03d.png")
brownian.motion(pch = 21, cex = 5, col = "red", bg = "yellow", 
    main = "Demonstration of Brownian Motion")
dev.off()

## filenames with a wildcard *
im.convert("bm*.png", output = "bm-animation1.gif")
## use GraphicsMagick
gm.convert("bm*.png", output = "bm-animation2.gif")

## or a filename vector
bm.files = sprintf("bm%03d.png", 1:20)
im.convert(files = bm.files, output = "bm-animation3.gif")

ani.options(oopt)
setwd(owd)

Run the code above in your browser using DataCamp Workspace