liveBook · Manning

Base64

As explained in Data Analysis with LLMs

Base64 encoding is a binary-to-text encoding scheme that represents binary data using a restricted set of printable characters.

Base64 represents binary data as a printable string using a 64-character alphabet. It groups three bytes (24 bits) into four characters (6 bits each). For images sent to GPT-4o, encode the binary image data with Base64, then decode the result as UTF-8 text for inclusion in a prompt. section 6.3.2

Encoding a local image

Read a picture in binary mode and encode its bytes with Python’s base64 library. In a people-tagging workflow, the encoded images are paired with instructions asking GPT-4o whether two pictures show the same person. section 6.3.2 section 6.3.4

with open(image_path, 'rb') as image_file:
    encoded = base64.b64encode(image_file.read())

This Python snippet reads an image file as bytes and Base64-encodes it. section 6.3.2

The same conversion applies to video frames: encode a frame as a JPEG image, Base64-encode its binary buffer, and decode the result as UTF-8 before adding it to a prompt. section 6.4.2

How Data Analysis with LLMs covers it

How deep it goes
Defines the 64-character encoding and three-byte-to-four-character grouping, then demonstrates Python encoding and UTF-8 conversion.
Examples
Uses private pictures, person-tagging comparisons, and JPEG video frames as encoding scenarios.
What you can do after
Apply Python’s base64 library to encode image bytes, then decode the result as UTF-8 for a prompt.
How it connects
Links binary image data with UTF-8 encoding and multimodal prompts.

Also explained in

Compare how 7 books explain Base64 →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Analysis with LLMs. The section links point to the parts of the book it draws on.