Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docling_core/types/doc/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import typing
import warnings
from collections.abc import Sequence
from dataclasses import dataclass
from enum import Enum
from io import BytesIO
from pathlib import Path
Expand All @@ -26,6 +25,8 @@
)
from urllib.parse import unquote

import cv2
import numpy as np
import pandas as pd
import yaml
from PIL import Image as PILImage
Expand Down Expand Up @@ -1109,9 +1110,8 @@ def validate_mimetype(cls, v):
@classmethod
def from_pil(cls, image: PILImage.Image, dpi: int) -> Self:
"""Construct ImageRef from a PIL Image."""
buffered = BytesIO()
image.save(buffered, format="PNG")
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
_, buffered = cv2.imencode(".png", cv2.cvtColor(np.array(image), cv2.COLOR_RGBA2BGRA))
img_str = base64.b64encode(buffered.tobytes()).decode("utf-8")
img_uri = f"data:image/png;base64,{img_str}"
return cls(
mimetype="image/png",
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies = [
'typer (>=0.12.5,<0.25.0)',
'latex2mathml (>=3.77.0,<4.0.0)',
"defusedxml (>=0.7.1, <0.8.0)",
"opencv-python-headless>=4.13.0.92",
]

[project.urls]
Expand Down
21 changes: 21 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading