Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an antialiasing method for Python PIL?

Tags:

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?

like image 488
whi Avatar asked Jan 16 '13 02:01

whi


People also ask

What is anti-aliasing Python?

As you can see, anti-aliasing has reduced the jaggedness and created a "smoother" look. This is achieved by blending the pixels on the edge of the text with the background. The jaggs are not completely opaque, but are partially transparent.

What is image antialias?

Antialiasing is a technique used in digital imaging to reduce the visual defects that occur when high-resolution images are presented in a lower resolution. Aliasing manifests itself as jagged or stair-stepped lines (otherwise known as jaggies) on edges and objects that should otherwise be smooth.

How do I reduce the size of an image in Python?

To resize an image, you call the resize() method on it, passing in a two-integer tuple argument representing the width and height of the resized image. The function doesn't modify the used image; it instead returns another Image with the new dimensions.

What is meant by anti-aliasing?

Anti-aliasing is the smoothing of jagged edges in digital images by averaging the colors of the pixels at a boundary. The letter on the left is aliased. The letter on the right has had anti-aliasing applied to make the edges appear smoother.


2 Answers

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.ANTIALIAS, e.g.:

im = im.resize((width // 2, height // 2), resample=Image.ANTIALIAS) 
like image 61
Mark Ransom Avatar answered Sep 24 '22 03:09

Mark Ransom


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.

like image 20
KevinC Avatar answered Sep 25 '22 03:09

KevinC