Is it possible to insert an animated image into Mathematica notebook?

The credits go to belisarius and the Mathematica help (ref/format/GIF), but I thought the comment would be worth an answer.

Import["ExampleData/cellularautomaton.gif", "Animation"]

Mathematica graphics


Unfortunately I don't know of any simple and convenient ways.

You can import the GIF first:

frames = Import["http://i.imgur.com/ivfdq.gif"];

Then you can use ListAnimate to get an animation:

ListAnimate[frames]

For completeness I'll mention that pre-6 versions could also animate. Scan[Print, frames] will give you each frame in separate cells. Now close the cell group by double clicking its bracket and press Ctrl-Y or Ctrl-Shift-Y to start the animation. This still works in version 8.


Here is one more attempt to get almost the exact appearance of an animated GIF without the playback controls. I don't recommend putting too many of these into a notebook, though:

makeAnimation[list_, delayList_: {.03}] := 
 DynamicModule[{l = Length[list], delays = Abs@Flatten[{delayList}], 
   times, totalTime, delta = .03, frames}, 
  times = Round[.5 + PadRight[delays, l, delays]/delta];
  frames = 
   Flatten@Table[Table[list[[i]], {times[[i]]}], {i, Length[times]}];
  totalTime = Length[frames];
  EventHandler[
   Dynamic[frames[[Clock[{1, totalTime, 1}, totalTime delta]]], 
    TrackedSymbols -> {}], {"MouseUp", 2} :> Null]]

makeAnimation[
 Import["ExampleData/cellularautomaton.gif", "ImageList"]]

gif

You can copy this animation by selecting its cell bracket. It's persistent across notebooks, too.