I want to convert any .gif in HTML on Mathematica and keep the animation of the gif. For this I use this function:
Export["output.html", gif, "HTML"]
But after export, I lose all gif animation on HTML.
Have you some idea?
I want to convert any .gif in HTML on Mathematica and keep the animation of the gif. For this I use this function:
Export["output.html", gif, "HTML"]
But after export, I lose all gif animation on HTML.
Have you some idea?
It seems when you export AnimatedImage or a list of frames to HTML, Mathematica give you a notebook interface that does not animate, is slower (took 10 seconds to export on SSD), and generates more than one file.
If you want to just export a GIF into a single HTML file, we can use an HTML template like below:
ClearAll[ExportGIFToHTML];
ExportGIFToHTML[file_, frames_] :=
Block[{dimensions = ImageDimensions @ First @ frames},
Export[file, StringTemplate["<!DOCTYPE html>
<html lang="en">
<head>
<title>GIF</title>
</head>
<body>
<img src='data:image/gif;base64,image-data' width='width'
height='height'></img>
</body>
</html>"][<|
"image-data" ->
ExportString[ExportString[frames, "GIF"], "Base64"],
"width" -> First @ dimensions, "height" -> Last @ dimensions|>],
"String"]
]
Let's generate a couple of frames:
frames =
Table[ListLinePlot[RandomInteger[5, 5], PerformanceGoal -> "Speed"],
5];
Then call the function (Took less than a second):
ExportGIFToHTML["C:\\test.html", frames]
Output:
You can play with the Export options to change the animation setting.