You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

streamlit-image-gallery-enhanced

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

streamlit-image-gallery-enhanced

Enhanced Streamlit component for displaying images in a responsive grid with hover effects and click callbacks

1.0.1
pipPyPI
Maintainers
1

PyPI version Python

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

ParameterTypeDefaultDescription
imagesList[Dict]RequiredList of image dictionaries
max_colsint2Maximum number of columns
max_rowsint2Maximum number of rows
gapint10Gap between images (px)
max_widthint400Container max width (px)
keystrNoneUnique component key

Returns

  • int | None: Index of clicked image (0-based), or None if no click

🎨 Styling Examples

streamlit_image_gallery(
    images=images,
    max_cols=5,
    max_rows=3, 
    gap=20,
    max_width=1200
)
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.

Keywords

streamlit

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts