views:

879

answers:

2

My site is full of rounded corners on every box and picture, except for the thumbnails of user uploaded photos.

How can I use the Python Imaging Library to 'draw' white or transparent rounded corners onto each thumbnail?

+5  A: 

From Fredrik Lundh:

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.

http://mail.python.org/pipermail/python-list/2008-January/472508.html

Rob Ottaway
A: 

Might it not be a better idea (assuming HTML is the output) to use HTML and CSS to put some rounded borders on those pictures? That way, if you want to change the look of your site, you don't have to do any image reprocessing, and you don't have to do any image processing in the first place.

Kibbee