Y
Y
YaroslavS2015-12-03 20:32:04
Python
YaroslavS, 2015-12-03 20:32:04

How to set line width when drawing primitives?

Hello, I use pillow, I draw some kind of primitive, for example, an ellipse

import Image, ImageDraw
image = Image.new('RGBA', (200, 200))
draw = ImageDraw.Draw(image)
draw.ellipse((20, 180, 180, 20), fill = 'blue', outline ='blue')

How to set the line thickness, for example 2 pixels?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TomasHuk, 2015-12-04
@YaroslavS

As I understand it, by regular means in any way.
You can draw two ellipses with a 1 pixel offset:

from PIL import Image, ImageDraw
image = Image.new('RGBA', (200, 200))
draw = ImageDraw.Draw(image)
draw.ellipse((20, 25, 100, 150), fill = None, outline ='blue')
draw.ellipse((19, 24, 101, 151), fill = None, outline ='blue')
del draw
image.show("test.png", "PNG")

By the way, you can set the thickness in the line:
draw.line((0, 0) + image.size, fill=128, width=5)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question