Create an HTML element with text and an image, displayed inline.
Note that depending on where you are placing the output in the table, you may want to wrap it in GT.html().
Parameters
text:str
The text to display alongside the image.
img_url:str
The URL of the image to display. This can be a filepath or an image on the web.
height:int=30
The height of the image in pixels.
gap:float=3.0
The spacing between the text and the image in pixels.
left:bool=False
If True, the image is displayed to the left of the text.
alt_text:str=''
The alternative text for the image, used for accessibility and displayed if the image cannot be loaded.
Returns
:str
A string with html content of the combined image and text. Depending on where you are placing the output in the table, you may want to wrap it in GT.html().
Examples
import pandas as pdfrom great_tables import GT, md, htmlimport gt_extras as gtedf = pd.DataFrame( {"Player": ["Josh Hart", "Jalen Brunson"],"Points": [1051, 1690],"Assists": [453, 475], })hart_img = gte.add_text_img( text="Josh Hart", img_url="https://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/3062679.png",)brunson_img = gte.add_text_img( text="Jalen Brunson", img_url="https://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/3934672.png",)df["Player"] = [hart_img, brunson_img]gt = ( GT(df, rowname_col="Player") .tab_source_note(md("Images and data courtesy of [ESPN](https://www.espn.com)")))gt
We can even apply the add_text_img() function to content outside of body/stub cells. We must remember to wrap the output in GT.html() so the table renders the element properly.