How to show local gif image?

Hi,
I want to show gif image in streamlit app. Like the st.image function doesn’t support gif format. And I try to use st.markdown:

st.markdown('<img src="./png_to_gif.gif"/>', unsafe_allow_html=True)

but still not work. So how can I do. Thanks very much.

Dave

How about this:

import streamlit as st

st.markdown("![Alt Text](https://media.giphy.com/media/vFKqnCdLPNOKc/giphy.gif)")

1 Like

Hi randyzwitch:
Thanks for your reply. But I want to show local gif file, the st.markdown does not support the local image file.
Dave

import streamlit as st
import base64

"""### gif from url"""
st.markdown("![Alt Text](https://media.giphy.com/media/vFKqnCdLPNOKc/giphy.gif)")

"""### gif from local file"""
file_ = open("/home/rzwitch/Desktop/giphy.gif", "rb")
contents = file_.read()
data_url = base64.b64encode(contents).decode("utf-8")
file_.close()

st.markdown(
    f'<img src="data:image/gif;base64,{data_url}" alt="cat gif">',
    unsafe_allow_html=True,
)

Feature request: https://github.com/streamlit/streamlit/issues/1566

1 Like

With no markdown ==> st.image("my_logo.gif) work

Unfortunately right now, st.image only works with JPG or PNG, but there’s no reason it can’t work with GIF in the future.

ah ok I use st.image() but my logo is not an animated image, sorry

Hi, randyzwitch:
the second solution is what i want. Thanks very much.
Dave

1 Like