1

I am trying to draw a line in a project where I tag some images. Here is my code :

header_img = Image.open("1.jpg") 
header1_img = header_img.resize((610, 320), Image.ANTIALIAS)
draw = ImageDraw.Draw(header1_img)
draw.line(((620, 100), (500, -30)), fill=(23,53,177,255), width=30)
header1_img.save("2.jpg", subsampling=0, quality=100)

This is the result

As you can see the line isn't smooth at all. How to do it properly ?

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
CommYov
  • 29
  • 7
  • I don't know but the keyword is probably "anti-aliasing". – Andras Deak -- Слава Україні Nov 07 '17 at 10:51
  • @AndrasDeak I found a thread on stack overflow but that seems overly complicated... I'd rather just draw the line straight then rotate the whole image – CommYov Nov 07 '17 at 10:56
  • The line is naturally going to look a lot nicer if you make it an exact 45° angle (difference in X coordinates equal to difference in Y coordinates - you currently have 120 X, but 130 Y). – jasonharper Nov 16 '17 at 13:28
  • Thanks a lot @jasonharper. Could you tell me how you did manage to find the X & Y coordinates ? – CommYov Nov 17 '17 at 10:05
  • Since you are resizing the image (I believe making it smaller), you could draw before resizing, the resizing would then do some the antialiasing. Yet this won't come close to good SVG rendering. – Daniel F Mar 13 '21 at 11:25

0 Answers0