Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

HWC BGR 888 Image to Base64 URI

A specialized utility for converting OpenCV-compatible HWC BGR 888 images to Base64-encoded data URIs. Can be used with the OpenAI Chat Completions API.

Usage with OpenAI Chat Completions API

from __future__ import print_function
import cv2

from hwc_bgr_888_image_to_base64_uri import hwc_bgr_888_image_to_base64_uri
from openai import OpenAI


# Initialize client
client = OpenAI(
    # For Ollama local endpoint
    base_url='http://localhost:11434/v1/',
    api_key='ollama', # Required parameter (ignored by Ollama)
)

# 1. Load image using OpenCV (native BGR format)
image = cv2.imread('input.jpg')

# 2. Convert to API-compliant URI (auto-resizes to 512px longest edge)
uri = hwc_bgr_888_image_to_base64_uri(
    image,
    max_long_edge=512, # Recommended for most vision models
    output_format_extension=u'.jpg' # Or u'.png' for quality
)

# 3. Structure chat completions request
response = client.chat.completions.create(
    model=u"llava",
    messages=[
        {
            u"role": u"user",
            u"content": [
                {u"type": u"text", u"text": u"What's in this image?"},
                {
                    u"type": u"image_url",
                    u"image_url": {
                        u"url": uri # Our generated URI
                    }
                }
            ]
        }
    ]
)

print(response.choices[0].message.content)

For more information:

Contributing

Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.

License

This project is licensed under the MIT License.

Release files for hwc-bgr-888-image-to-base64-uri 0.1.0a0

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

Source distribution (sdist)

Source distribution for hwc-bgr-888-image-to-base64-uri 0.1.0a0
File Size Uploaded
hwc_bgr_888_image_to_base64_uri-0.1.0a0.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hwc-bgr-888-image-to-base64-uri 0.1.0a0
File Interpreter ABI Platform
hwc_bgr_888_image_to_base64_uri-0.1.0a0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 8.0 kB

Release files / hwc_bgr_888_image_to_base64_uri-0.1.0a0.tar.gz

Download URL hwc_bgr_888_image_to_base64_uri-0.1.0a0.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f8aee3fccfd520958784f3a56ef613f65c2932689f086d195ee41573ca41fffc
BLAKE2b-256 checksum
How to use checksums
17b72a36ce612e520228c032e14fab176e3ef3882e17d42b79b264000545315d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Release files / hwc_bgr_888_image_to_base64_uri-0.1.0a0-py2.py3-none-any.whl

Download URL hwc_bgr_888_image_to_base64_uri-0.1.0a0-py2.py3-none-any.whl
Size 4.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
1fa7047d9ce106c02e0748a2c86e6553f2a5cf82d41a8cd38fdb240cfd105119
BLAKE2b-256 checksum
How to use checksums
5f4737ef13a986f81d8bbd03ceabfec84a3fcea3163358efae8d30d4e747ec28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.1.0a0 This release

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