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)