Enhanced Streamlit component for displaying images in a responsive grid with hover effects and click callbacks
Project description
Streamlit Image Gallery Enhanced 🖼️✨
An enhanced Streamlit component for displaying images in a responsive grid with hover effects, click callbacks, and modern HTML structure.
🚀 Features
- ✨ Hover effects with smooth transitions
- 👆 Click callbacks - get the index of clicked images
- 🎨 No Material-UI dependency - pure HTML/CSS
- 📱 Responsive grid layout using CSS Grid
- 🖼️ Fixed image dimensions with object-fit cover
- 🎯 Clickable titles below each image
- ⚡ Lightweight - 22KB smaller than Material-UI version
- 🔧 Customizable gap, columns, and dimensions
📦 Installation
pip install streamlit-image-gallery-enhanced
🎯 Quick Start
import streamlit as st
from streamlit_image_gallery_enhanced import streamlit_image_gallery
# Define your images
images = [
{
"src": "https://images.unsplash.com/photo-1718439111428-f6ef86aae18d",
"title": "Beautiful Flowers"
},
{
"src": "https://images.unsplash.com/photo-1718554517666-2978ede88574",
"title": "Cute Bird"
},
# Add more images...
]
# Display gallery with click callback
clicked_index = streamlit_image_gallery(
images=images,
max_cols=3,
gap=10,
key="gallery"
)
# Handle clicks
if clicked_index is not None:
st.write(f"You clicked: {images[clicked_index]['title']}")
🎨 Advanced Usage
Custom Styling
streamlit_image_gallery(
images=images,
max_cols=4, # Maximum columns
max_rows=2, # Maximum rows
gap=15, # Gap between images
max_width=800, # Container max width
key="my_gallery" # Unique key for state
)
Image Structure
images = [
{
"src": "https://example.com/image.jpg", # Required: image URL
"title": "Image Title" # Required: image title
}
]
✨ What's New in Enhanced Version
🎨 Visual Improvements
- Hover Effects: Light blue background (
#f0f8ff) on hover - Smooth Transitions: 0.2s ease animations
- Fixed Dimensions: 150px height, 100% width with object-fit cover
- Clean Titles: Clickable text below images (no overlay)
🏗️ Technical Improvements
- Pure HTML: No Material-UI dependency (22KB smaller)
- CSS Grid: Modern responsive layout
- React State: Proper hover state management
- Click Callbacks: Returns image index to Python
🎯 Interactive Features
- Both image and title clickable
- Index tracking for click handling
- Keyboard accessible
- Touch-friendly for mobile
🔧 Component Structure
<div style="display: grid; grid-template-columns: repeat(cols, 1fr);">
<div> <!-- Container with hover effects -->
<img style="height: 150px; width: 100%; object-fit: cover;" />
<p>Title Text</p>
</div>
</div>
📋 API Reference
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
images |
List[Dict] |
Required | List of image dictionaries |
max_cols |
int |
2 |
Maximum number of columns |
max_rows |
int |
2 |
Maximum number of rows |
gap |
int |
10 |
Gap between images (px) |
max_width |
int |
400 |
Container max width (px) |
key |
str |
None |
Unique component key |
Returns
int | None: Index of clicked image (0-based), orNoneif no click
🎨 Styling Examples
Large Gallery
streamlit_image_gallery(
images=images,
max_cols=5,
max_rows=3,
gap=20,
max_width=1200
)
Compact Gallery
streamlit_image_gallery(
images=images,
max_cols=2,
gap=5,
max_width=300
)
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
MIT License - see LICENSE file for details.
🙏 Acknowledgments
Based on the original streamlit-image-gallery by virtUOS, enhanced with modern features and improved UX.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file streamlit_image_gallery_enhanced-1.0.1.tar.gz.
File metadata
- Download URL: streamlit_image_gallery_enhanced-1.0.1.tar.gz
- Upload date:
- Size: 428.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01cc59ef14159992dace0772e2b8ad8a11e34f0302eeedfd80690db813967ea4
|
|
| MD5 |
2a9b3db4d674a870c291203199b85a31
|
|
| BLAKE2b-256 |
3b9ddff499144c1f4bb875ec518dee5f7a3a9ee68bd038fd8b412b0632dad812
|
File details
Details for the file streamlit_image_gallery_enhanced-1.0.1-py3-none-any.whl.
File metadata
- Download URL: streamlit_image_gallery_enhanced-1.0.1-py3-none-any.whl
- Upload date:
- Size: 429.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55595f91cfa93d8ed39c55c69abf0b5059768f91d0f342ec56f8763354c368e1
|
|
| MD5 |
d42c4aa5ab6b2683bb66ea03b4964e0a
|
|
| BLAKE2b-256 |
b4eb97b025a740d75a5bbe5892a87514bfb10a9b9050b447ae0ab97fc2bccf97
|