使用PIL在照片上绘制圆角

时间:2022-11-08 00:25:37

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?

如何使用Python Imaging Library在每个缩略图上“绘制”白色或透明圆角?

2 个解决方案

#1


From Fredrik Lundh:

来自Fredrik Lundh:

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

创建一个带圆角的遮罩图像(使用您喜欢的图像编辑器或使用ImageDraw / aggdraw或其他一些)。

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.

    如果你想要透明的角落,创建一个与缩略图大小相同的“L”图像,使用“粘贴”在该图像中添加角落蒙版,然后使用“putalpha”将alpha图层附加到缩略图。

  • 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

#2


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.

使用HTML和CSS在这些图片上放置一些圆形边框可能不是一个更好的主意(假设HTML是输出)?这样,如果您想要更改站点的外观,则不必进行任何图像重新处理,并且您不必首先进行任何图像处理。

#1


From Fredrik Lundh:

来自Fredrik Lundh:

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

创建一个带圆角的遮罩图像(使用您喜欢的图像编辑器或使用ImageDraw / aggdraw或其他一些)。

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.

    如果你想要透明的角落,创建一个与缩略图大小相同的“L”图像,使用“粘贴”在该图像中添加角落蒙版,然后使用“putalpha”将alpha图层附加到缩略图。

  • 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

#2


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.

使用HTML和CSS在这些图片上放置一些圆形边框可能不是一个更好的主意(假设HTML是输出)?这样,如果您想要更改站点的外观,则不必进行任何图像重新处理,并且您不必首先进行任何图像处理。