Skip to content

Commit

Permalink
Add gif display to _repr_html_ for jupyter notebooks (#171)
Browse files Browse the repository at this point in the history
Allows jupyter notebooks to automatically display gif animations,
similarly to the video formats.

Follow up to https://github.com/napari/napari-animation/pull/170/files

See comment here
#170 (comment)
  • Loading branch information
GenevieveBuckley authored Dec 31, 2023
1 parent 95801a5 commit 5760ee2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions napari_animation/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ def _on_active_keyframe_changed(self, event):

def _repr_html_(self):
if self._filename is None:
return 'Video animation not yet available (use the "animate" method to generate it).'
html = 'Video animation not yet available (use the "animate" method to generate it).'
elif str(self._filename).endswith(".gif"):
html = f'<img src="{self._filename}">'
else:
html = f'<video width="100%" height="100%" controls> <source src="{self._filename}"> </video>'
return html
return html

0 comments on commit 5760ee2

Please sign in to comment.