Skip to main content

A modern image widget for Jupyter notebooks and Python environments

Project description

Moimage

A modern image widget for Jupyter notebooks and Python environments.

Installation

Using UV (recommended):

uv add moimage

Or using pip:

pip install moimage

Development Setup

  1. Clone the repository:
git clone <repository-url>
cd moimage
  1. Install with UV:
uv sync --dev
  1. Install in development mode:
uv pip install -e .

Usage

Basic Image Display

from moimage import ImageWidget
from PIL import Image

# Load image from file path
widget = ImageWidget("path/to/image.jpg")
display(widget)

# Load image from URL
widget = ImageWidget("https://example.com/image.png")
display(widget)

# Load from PIL Image object
pil_img = Image.open("image.jpg")
widget = ImageWidget(pil_img)
display(widget)

# Get image information
info = widget.get_image_info()
print(f"Image size: {info['width']}x{info['height']}")

Image Processing with Modular Widgets

from moimage import ImageOutlineWidget, ImageDownloadWidget, ImageClipboardWidget

# Create outline widget
outline_widget = ImageOutlineWidget(
    "https://example.com/image.jpg",
    outline_width=10,
    outline_color="#FF0000"
)

# Create utility widgets that automatically sync
download_widget = ImageDownloadWidget(
    image_src=outline_widget.processed_image_src,
    filename="outlined_image",
    format="png"
)

clipboard_widget = ImageClipboardWidget(
    image_src=outline_widget.processed_image_src
)

# In Marimo, these widgets automatically react to changes!

Complete Marimo Example

import marimo as mo
from moimage import ImageOutlineWidget, ImageDownloadWidget, ImageClipboardWidget

# Create widgets
outline = mo.ui.anywidget(ImageOutlineWidget("image.jpg"))
download = mo.ui.anywidget(ImageDownloadWidget(
    image_src=outline.value.processed_image_src
))
clipboard = mo.ui.anywidget(ImageClipboardWidget(
    image_src=outline.value.processed_image_src
))

# Display widgets - they automatically sync through Marimo's reactivity!
mo.hstack([outline, mo.vstack([download, clipboard])])

Available Widgets

Core Widget

  • ImageWidget: Display images with metadata information
    • Supports file paths, URLs, and PIL Image objects
    • Shows image dimensions, format, and source type
    • Automatic base64 encoding for local files
    • Error handling for invalid images

Processing Widgets

  • ImageOutlineWidget: Apply outline/glow effects around image shapes
    • Creates outline effects around non-transparent pixels (perfect for PNGs)
    • Configurable outline width (1-50px) and color
    • Canvas-based processing with alpha channel detection
    • Inherits from ImageWidget for full image loading capabilities
    • Reset functionality to return to original image

Utility Widgets

  • ImageDownloadWidget: Download images from any source

    • Configurable filename and format (PNG, JPG, WebP)
    • Works with base64 data URLs and remote URLs
    • Cross-origin image handling with canvas conversion
    • Clean, simple interface
  • ImageClipboardWidget: Copy images to system clipboard

    • Modern Clipboard API with fallback support
    • Handles base64 and remote images automatically
    • Visual feedback and error handling
    • Cross-browser compatibility

Features

  • Built on AnyWidget framework for seamless Jupyter integration
  • Modern JavaScript/HTML frontend with Python backend
  • Reactive state management with traitlets
  • Extensible architecture for custom widgets
  • TypeScript support for frontend development

Creating Custom Widgets

import anywidget
import traitlets

class MyCustomWidget(anywidget.AnyWidget):
    _esm = """
    function render({ model, el }) {
        // Your JavaScript rendering logic here
        let value = model.get("value");
        // ... create DOM elements and event handlers
    }
    export default { render };
    """
    
    value = traitlets.Unicode("").tag(sync=True)

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moimage-0.1.0.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

moimage-0.1.0-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

Details for the file moimage-0.1.0.tar.gz.

File metadata

  • Download URL: moimage-0.1.0.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.6

File hashes

Hashes for moimage-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4b3280ce1f26473e7549cde2e4774ea370536b03c2377de5f65d9611ad01c7a5
MD5 1c0b732a371b866f362a13274136e52b
BLAKE2b-256 235bf2c6735fd9ab1dd096c948deac9604a95fd174fe6fc37c05c621148200cc

See more details on using hashes here.

File details

Details for the file moimage-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: moimage-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 37.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.6

File hashes

Hashes for moimage-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32523aad77d568fbddfed1ac5d146f1986e2530278ba3122f9dda036e98a9932
MD5 7a10b6c85eadbabd758262b777c7310c
BLAKE2b-256 d294b247544c5737fc6f6c3c19073d5697a894fc830f9259184918111ed08d3f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page