12
$\begingroup$
frames=Table[Plot[Sin[x(1+a x)],{x,0,6}],{a,0,2,0.2}];
Export["test.gif",frames]

The above code runs in version 9.0 to get a infinite looping GIF animation, but in recent versions it only loops once.
I know I can specify the option "AnimationRepetitions" -> Infinity. Can this option be the default when exporting GIF? I have tried SetOptions[Export, "AnimationRepetitions" -> Infinity], it doesn't work.

$\endgroup$
2
  • 3
    $\begingroup$ I'm unclear what you are looking for exactly. If I had a number of animations to export, I would write a simple myExport routine that would set the option for me. If you need it every session, you could put the definition in init.m. It doesn't seem much different to me that SetOptions (if that actually worked). $\endgroup$ – Michael E2 Jan 22 at 5:56
  • 3
    $\begingroup$ I also struggle with this ever since they switched the default behavior. Is there a specific reason they changed this? In any case, I will definitely use your trick @MichaelE2 . Thanks! $\endgroup$ – Emy Jan 22 at 7:12
8
$\begingroup$

The final internal System`Convert`CommonGraphicsDump`exportImageListToGIF does not have Options and outer System`Convert`CommonGraphicsDump`exportImageListToRasterFormat has but handles other raster formats so it is not desirable to affect them.

What can be done is to re-register gif export. That needs to be done once per session, e.g. in init.m:

Begin["System`ConvertersDump`"]

ImportExport`RegisterExport[
   "GIF",
   System`Convert`CommonGraphicsDump`ExportElementsToRasterFormat[
   "GIF", ##, "AnimationRepetitions" -> Infinity (*here's the patch*)] &,
   "Sources" -> {"Convert`CommonGraphics`"},
   "DefaultElement" -> Automatic,
   "Options" -> 
  SortBy[{"AnimationDuration", "AnimationRepetitions", Background, 
    "Comments", "ControlAppearance", "DisplayDurations", Dithering, 
    "FrameRate", ImageSize, "Interlaced", 
    "PreserveManipulateInitialization", "TransparentColor"}, ToString],
   "BinaryFormat" -> True
 ]

End[]

or you'd need to modify $InstallationDirectory\SystemFiles\Formats\GIF\Export.m but modifying installation dir is not recommended.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.