MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / pil_to_data_uri

Function pil_to_data_uri

utils/poster_eval_utils.py:51–65  ·  view source on GitHub ↗

Convert a PIL.Image to a base-64 data URI suitable for the OpenAI/vLLM 'image_url' block. fmt = 'PNG' (lossless) or 'JPEG' (smaller, 0-100 quality).

(img: Image.Image, fmt: str = "PNG")

Source from the content-addressed store, hash-verified

49from transformers import AltCLIPProcessor, AltCLIPModel
50
51def pil_to_data_uri(img: Image.Image, fmt: str = "PNG") -> str:
52 """
53 Convert a PIL.Image to a base-64 data URI suitable for
54 the OpenAI/vLLM 'image_url' block.
55 fmt = 'PNG' (lossless) or 'JPEG' (smaller, 0-100 quality).
56 """
57 buf = io.BytesIO()
58 if fmt.upper() == "JPEG":
59 img.save(buf, format="JPEG", quality=90)
60 mime = "image/jpeg"
61 else:
62 img.save(buf, format="PNG")
63 mime = "image/png"
64 b64 = base64.b64encode(buf.getvalue()).decode()
65 return f"data:{mime};base64,{b64}"
66
67def md_to_blocks(
68 md: str,

Callers 3

md_to_blocksFunction · 0.70
get_visual_pplFunction · 0.70
compute_poster_image_pplFunction · 0.70

Calls 1

saveMethod · 0.45

Tested by

no test coverage detected