Skip to content

Instantly share code, notes, and snippets.

@MartinThoma
Created May 26, 2022 11:27
Show Gist options
  • Save MartinThoma/a261c0f5e1ec4e0f39695e10d91bf8ac to your computer and use it in GitHub Desktop.
Save MartinThoma/a261c0f5e1ec4e0f39695e10d91bf8ac to your computer and use it in GitHub Desktop.
from PIL import Image, ImageDraw # pip install pillow for PIL
# Define the canvas size
width = 1500
height = 500
im = Image.new("RGB", (width, height), (255, 255, 255))
draw = ImageDraw.Draw(im)
# Draw a single line
x1, y1 = 10, 20
x2, y2 = 1000, 50
color = (0, 0, 0) # rgb
draw.line((x1, y1, x2, y2), fill=color)
# Save the image as a PNG
im.save("rectangles.png", "PNG")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment