> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ag2.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# autogen.agentchat.contrib.img_utils.message_formatter_pil_to_b64

<code class="doc-symbol doc-symbol-heading doc-symbol-function" />

#### message\_formatter\_pil\_to\_b64

```python theme={null}
message_formatter_pil_to_b64(messages: list[dict[str, Any]]) -> list[dict[str, Any]]
```

Converts the PIL image URLs in the messages to base64 encoded data URIs.<br />This function iterates over a list of message dictionaries. For each message,
if it contains a 'content' key with a list of items, it looks for items
with an 'image\_url' key. The function then converts the PIL image URL
(pointed to by 'image\_url') to a base64 encoded data URI.<br />Parameters: <br />    messages (List\[Dict]): A list of message dictionaries. Each dictionary
may contain a 'content' key with a list of items,
some of which might be image URLs.<br />Returns: <br />    List\[Dict]: A new list of message dictionaries with PIL image URLs in the
'image\_url' key converted to base64 encoded data URIs.<br />Example Input: <br />    \`\`\`python
\[
\{'content': \[\{'type': 'text', 'text': 'You are a helpful AI assistant.'}], 'role': 'system'},
\{'content': \[
\{'type': 'text', 'text': "What's the breed of this dog here?"},
\{'type': 'image\_url', 'image\_url': \{'url': a PIL.Image.Image}},
\{'type': 'text', 'text': '.'}],
'role': 'user'}
]

````

Example Output: <br/>    ```python
[
    \{'content': [\{'type': 'text', 'text': 'You are a helpful AI assistant.'}], 'role': 'system'},
    \{'content': [
        \{'type': 'text', 'text': "What's the breed of this dog here?"},
        \{'type': 'image_url', 'image_url': \{'url': a B64 Image}},
        \{'type': 'text', 'text': '.'}],
    'role': 'user'}
]
````

<b>Parameters:</b>

| Name       | Description                             |
| ---------- | --------------------------------------- |
| `messages` | **Type:** list\[dict\[str, typing.Any]] |

<b>Returns:</b>

| Type                          | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| list\[dict\[str, typing.Any]] | List\[Dict]: A new list of message dictionaries with PIL image URLs in the 'image\_url' key converted to base64 encoded data URIs. Example Input: `python [ \{'content': [\{'type': 'text', 'text': 'You are a helpful AI assistant.'}], 'role': 'system'}, \{'content': [ \{'type': 'text', 'text': "What's the breed of this dog here?"}, \{'type': 'image_url', 'image_url': \{'url': a PIL.Image.Image}}, \{'type': 'text', 'text': '.'}], 'role': 'user'} ] ` Example Output: `python [ \{'content': [\{'type': 'text', 'text': 'You are a helpful AI assistant.'}], 'role': 'system'}, \{'content': [ \{'type': 'text', 'text': "What's the breed of this dog here?"}, \{'type': 'image_url', 'image_url': \{'url': a B64 Image}}, \{'type': 'text', 'text': '.'}], 'role': 'user'} ] ` |

<br />
