PIL question

Fredrik Lundh fredrik at pythonware.com
Wed Jan 9 08:03:05 EST 2008


Alex K wrote:

> Would anyone know how to generate thumbnails with rounded corners
> using PIL? I'm also considering imagemagick if PIL turns out not to be
> appropriate for the task.

create a mask image with round corners (either with your favourite image 
editor or using ImageDraw/aggdraw or some such).

in your program, load the mask image, and cut out the four corners using 
"crop".

then, for each image, create a thumbnail as usual, and use the corner 
masks on the corners of the thumbnail.

- if you want transparent corners, create an "L" image with the same 
size as the thumbnail, use "paste" to add the corner masks in that 
image, and then use "putalpha" to attach the alpha layer it to the 
thumbnail.

- if you want solid corners, use "paste" on the thumbnail instead, using 
a solid color as the source.

</F>




More information about the Python-list mailing list