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?
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?
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.
aggdraw (http://effbot.org/zone/aggdraw-index.htm) may be something you're interested in.
The aggdraw module implements the basic WCK 2D Drawing Interface on top of the AGG library. This library provides high-quality drawing, with anti-aliasing and alpha compositing, while being fully compatible with the WCK renderer.
The aggdraw module can be used with PIL or the WCK library (under Tkinter or native Windows). It can also be used as a stand-alone library.
im = im.resize((width // 2, height // 2), resample=Image.LANCZOS)
A new LANCZOS
constant was added instead of ANTIALIAS
.
When ANTIALIAS
was initially added, it was the only high-quality filter based on convolutions. It’s name was supposed to reflect this. Starting from Pillow 2.7.0 all resize method are based on convolutions. All of them are antialias from now on. And the real name of the ANTIALIAS
filter is LANCZOS
filter.
The ANTIALIAS
constant is left for backward compatibility and is an alias for LANCZOS
.