posted an update

I've improved the code with a minor change, where it once simply gave the user one generated image, it now makes 25 images within a GIF. Below is the improved code.

*Minor change but effective

import random import uuid

frames = []

from PIL import Image, ImageDraw, ImageOps def imagek(): run_id = uuid.uuid1()

print(f'Processing run_id: {run_id}')

def make_circular(im):
    im2 = Image.new('L', im.size)
    mask = Image.new("L", im.size)
    draw = ImageDraw.Draw(mask)
    draw.ellipse((0, 0) + im.size, fill=255)
    out = Image.composite(im, im2, mask)

    return out

image = Image.new('RGB', (128, 128))
width, height = image.size

rectangle_width = random.randint(1, 20)
rectangle_height = random.randint(1, 20)

number_of_squares = random.randint(6000, 10000)

draw_image = ImageDraw.Draw(image)
for i in range(number_of_squares):
    rectangle_x = random.randint(0, width)
    rectangle_y = random.randint(0, height)

    rectangle_shape = [
        (rectangle_x, rectangle_y),
        (rectangle_x + rectangle_width, rectangle_y + rectangle_height)]
    draw_image.rectangle(
        rectangle_shape,
        fill=(
            random.randint(0, 255),
            random.randint(0, 255),
            random.randint(0, 255)
        )
    )
circular_Image = make_circular(image)
frames.append(circular_Image)

# circular_Image.save(f'./output/{run_id}.png')

for i in range(25): imagek() frame_one = frames[0] frame_one.save("./output/circle.gif", format="GIF", append_images=frames, save_all=True, duration=100, loop=0)

Log in or sign up for Devpost to join the conversation.