pythonpython-imaging-libraryantialiasing

Is there an antialiasing method for Python PIL?


For lines and ellipses in PIL, the images are rough.

I found antialiasing only in resize and thumbnail.

Is there any way to do antialiasing when drawing a line or ellipse?


Solution

  • The only way to do it natively is with supersampling. Render your image at a multiple of the size you require, then resize it with resample=Image.LANCZOS, e.g.:

    im = im.resize((width // 2, height // 2), resample=Image.LANCZOS)
    

    If you have a very old version of PIL (before Pillow 2.7.0) you need to use ANTIALIAS instead of LANCZOS. The ANTIALIAS constant which was originally recommended with this answer has been deprecated for years, and was finally removed in Pillow 10.0.