Skip to main content

Image Zoom - Streamlit Component

This repository presents a Python Streamlit component that wraps HTML, CSS, and JS code, enabling the creation of an interactive image zoom application. Try online demo!

Installation

  • Install via pip:
pip install streamlit
pip install streamlit-image-zoom
  • Install via git clone:
git clone https://github.com/vgilabert94/streamlit-image-zoom

Documentation

Main function

def image_zoom(image: Union[Image.Image, np.ndarray],
                mode: Optional[str] = "default",
                size: Optional[Union[int, Tuple[int, int]]] = 512,
                keep_aspect_ratio: Optional[bool] = True,
                keep_resolution: Optional[bool] = False,
                zoom_factor: Optional[Union[float, int]] = 2.0,
                increment: Optional[float] = 0.2,
            ) -> HTML:

    return component

Parameters

  • image: The image to be displayed. It can be either a PIL Image or a NumPy array.
  • mode: The mode of interaction for zooming. Valid options are "default" (zoom on mousemove), "mousemove" (zoom on mousemove), "scroll" (zoom on scroll), "both" (zoom on both mousemove and scroll) or "dragmove" (Single-click to zoom in, click and drag to move the zoomed image). Default is "default".
  • size: The desired size of the displayed image. If an integer is provided, the image will be resized to have that size (width = height). If a tuple of integers (width, height) is provided, the image will be resized to fit within the specified dimensions while maintaining its aspect ratio. Default is 512.
  • keep_aspect_ratio: Whether to maintain the aspect ratio of the image during resizing. If True, the image will be resized while preserving its aspect ratio. If False, the image will be resized to exactly match the provided size without preserving aspect ratio. Default is True.
  • keep_resolution: Whether to keep the original resolution for zooming. If True, use the original resolution for zooming. If False, use the resized image for zooming. Default is False.
    Note: Setting this parameter to True may result in slower performance, especially for images with large sizes.
  • zoom_factor: The zoom factor applied to the image when zooming in. Default is 2.0.
  • increment: The increment value for adjusting the zoom level when scrolling. Should be between 0 and 1. Default is 0.2.

Modes

Here's a list explaining the operation of each mode in the app:

mousemove or default

As you move the mouse, the zoom level adjusts accordingly, providing a dynamic zoom experience.

scroll

Zooming is activated exclusively by scrolling (wheel).

both

This mode combines the functionalities of both "mousemove" and "scroll" modes, allowing users to navigate the image with a fixed zoom level. Zooming is activated by scrolling (using the mouse wheel) and moving the mouse cursor, offering flexibility in how users interact with the zoom feature.

dragmove

Drag and move mode Single-click to zoom in, click and drag to move the zoomed image, and double-click to zoom out.

Examples

import streamlit as st
from streamlit_image_zoom import image_zoom
from PIL import Image
import cv2

# Supported Image Formats
# PIL image
from PIL import Image
image = Image.open("images/building.jpg")

# Numpy array (opencv, scikit-image, etc)
import cv2
image = cv2.cvtColor(cv2.imread("image.jpg"), cv2.COLOR_BGR2RGB)

# Display image with default settings
image_zoom(image)

# Display image with custom settings
image_zoom(image, mode="scroll", size=(800, 600), keep_aspect_ratio=False, zoom_factor=4.0, increment=0.2)

License

Distributed under the MIT License. See LICENSE.txt for more information.

Contact

Vicent Gilabert

Linkedin

References

Metadata

Release files for streamlit-image-zoom 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for streamlit-image-zoom 0.0.4
File Size Uploaded
streamlit_image_zoom-0.0.4.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for streamlit-image-zoom 0.0.4
File Interpreter ABI Platform
streamlit_image_zoom-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / streamlit_image_zoom-0.0.4.tar.gz

Download URL streamlit_image_zoom-0.0.4.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ebd613e1656fbfd83cf38536c0218dc776b805c7a20c5a372797962b04c2c616
BLAKE2b-256 checksum
How to use checksums
54b0507c0802d07c539ba828f6ac5d258a45cf60112617937baed6729f1a4caa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.0

Release files / streamlit_image_zoom-0.0.4-py3-none-any.whl

Download URL streamlit_image_zoom-0.0.4-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e0a763c52729f452bd3bc2ea22eff1fa090bdb6cfa3c3f7141b8f9c1db11c28
BLAKE2b-256 checksum
How to use checksums
f0fd8def9900e032ff72d6d982991cba0f6a4bf27148f911faede96ffc0ef801
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.0

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page