As below, I displayed images that have URLs using markdown.
I thought it would be right-aligned, but it was not.
Here is my code and Output image.
Please let me know what was wrong and how to fix it.
import os, base64
import streamlit as st
import numpy as np
st.set_page_config(layout="wide")
@st.cache(allow_output_mutation=True)
def get_base64_of_bin_file(bin_file):
with open(bin_file, "rb") as f:
data = f.read()
return base64.b64encode(data).decode()
@st.cache(allow_output_mutation=True)
def get_img_with_href(local_img_path, target_url):
img_format = os.path.splitext(local_img_path)[-1].replace(".", "")
bin_str = get_base64_of_bin_file(local_img_path)
html_code = f"""
<a href="{target_url}">
<img src="data:image/{img_format};base64,{bin_str}" style="width:100%; height:100%" />
</a>"""
return html_code
cols = st.columns([1]*12+[6])
imgDir = {local image directory}
imgLs = np.sort(os.listdir(imgDir))
for idx in range(len(imgLs)):
gif_html = get_img_with_href(os.path.join(imgDir,imgLs[idx]), {URL})
cols[idx%12].markdown(gif_html, unsafe_allow_html=True)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.