ImageCard
The ImageCard helper displays an image (from a URL or a local file) inside a styled card, with an optional caption below it.
Basic Usage
Section titled “Basic Usage”Example: Image from URL
Section titled “Example: Image from URL”import mercury as mr
mr.ImageCard( src="https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg", caption="A cat loaded from a public URL")Example: Image from Local File
Section titled “Example: Image from Local File”import mercury as mr
mr.ImageCard( src="assets/plot.png", caption="Saved plot from the experiment")Caption
Section titled “Caption”Use caption to show a centered italic description below the image:
import mercury as mr
mr.ImageCard( src="assets/result.png", caption="Training result after 50 epochs")If caption="" (default), no caption element is rendered.
Sizing
Section titled “Sizing”Card Width
Section titled “Card Width”Use width to control the outer card width (CSS value):
import mercury as mr
mr.ImageCard( src="assets/result.png", width="420px")Default: "100%"
Fixed Image Height
Section titled “Fixed Image Height”Use height to create a fixed image area (useful when you want multiple cards aligned).
When height is provided, the image uses object-fit: contain.
import mercury as mr
mr.ImageCard( src="assets/result.png", height="240px", caption="Fixed-height preview")Default: None (natural image height)
Styling Options
Section titled “Styling Options”Rounded Corners
Section titled “Rounded Corners”import mercury as mr
mr.ImageCard( src="assets/result.png", rounded=False)Default: True
Border
Section titled “Border”import mercury as mr
mr.ImageCard( src="assets/result.png", show_border=False)Default: True
ImageCard Props
Section titled “ImageCard Props”src (required)
Section titled “src (required)”type: string
Image source. Can be:
- an
http://orhttps://URL, or - a local filesystem path (e.g.
assets/plot.png)
caption
Section titled “caption”type: string
Optional caption text shown below the image (centered and italic).
Default: ""
type: string
CSS width for the outer card (e.g. "100%", "400px").
Default: "100%"
height
Section titled “height”type: string | None
Fixed CSS height for the image area (e.g. "240px").
If None, the image uses its natural height.
Default: None
rounded
Section titled “rounded”type: bool
If True, apply theme border radius to the image area.
Default: True
show_border
Section titled “show_border”type: bool
If True, show a border around the card.
Default: True
type: string
Unique identifier to reuse the same widget instance.
ImageCardrenders immediately (it is a display helper) and does not return a value.- Local files are embedded as
data:URIs (base64), which makes them easy to render in the UI. - If
srcis neither a valid URL nor an existing file path, it is used as-is (so invalid paths will likely show a broken image). - Styling is aligned with the Mercury theme (
THEME) and is injected globally once per notebook session.