File size: 766 Bytes
19c33ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import numpy as np
from PIL import Image
import io
import base64


def generate_image(text):
    # Generate a random image
    image = np.random.randint(0, 256, size=(1028, 1028, 3), dtype=np.uint8)
    image = Image.fromarray(image)

    # Save the image to a byte buffer
    buffer = io.BytesIO()
    image.save(buffer, format="JPEG")
    image_bytes = buffer.getvalue()

    # Convert the image bytes to a base64-encoded string
    image_string = base64.b64encode(image_bytes).decode("utf-8")

    return image_string


# # Assume that `image_string` is the base64-encoded image string returned by `generate_image`
# image_bytes = base64.b64decode(generate_image(""))
# image = Image.open(io.BytesIO(image_bytes))
# image.show()  # Show the image in a new window