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:
- https://platform.openai.com/docs/api-reference/chat/create
- https://github.com/ollama/ollama/blob/main/docs/openai.md#curl
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
License
This project is licensed under the MIT License.
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hwc_bgr_888_image_to_base64_uri-0.1.0a0.tar.gz | 3.7 kB | Without provenance | Details for hwc_bgr_888_image_to_base64_uri-0.1.0a0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hwc_bgr_888_image_to_base64_uri-0.1.0a0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for hwc_bgr_888_image_to_base64_uri-0.1.0a0-py2.py3-none-any.whl |
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
|
Security for hwc-bgr-888-image-to-base64-uri 0.1.0a0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.