Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python枕头为圆形图像添加边框_Python_Pillow - Fatal编程技术网

Python枕头为圆形图像添加边框

Python枕头为圆形图像添加边框,python,pillow,Python,Pillow,我一直在四处寻找,但在任何地方都没有找到答案。我想做的是在圆形图像上添加一个白色边框。你们可能知道,当用枕头遮盖图像时,有一种奇怪的边界,这就是为什么我想改变它。我正在使用下面的代码对原始图像进行圆角处理,但是还不知道如何添加边框,因为它只会为原始图像创建一个矩形边框 def add_corners(self, im, rad): circle = Image.new('L', (rad * 2, rad * 2), 0) draw = ImageDraw.Dr

我一直在四处寻找,但在任何地方都没有找到答案。我想做的是在圆形图像上添加一个白色边框。你们可能知道,当用枕头遮盖图像时,有一种奇怪的边界,这就是为什么我想改变它。我正在使用下面的代码对原始图像进行圆角处理,但是还不知道如何添加边框,因为它只会为原始图像创建一个矩形边框

 def add_corners(self, im, rad):
        circle = Image.new('L', (rad * 2, rad * 2), 0)
        draw = ImageDraw.Draw(circle)
        draw.ellipse((0, 0, rad * 2, rad * 2), fill=255)
        alpha = Image.new('L', im.size, 255)
        w, h = im.size
        alpha.paste(circle.crop((0, 0, rad, rad)), (0, 0))
        alpha.paste(circle.crop((0, rad, rad, rad * 2)), (0, h - rad))
        alpha.paste(circle.crop((rad, 0, rad * 2, rad)), (w - rad, 0))
        alpha.paste(circle.crop((rad, rad, rad * 2, rad * 2)), (w - rad, h - rad))
        im.putalpha(alpha)
        return im
希望任何人都知道如何做到这一点,任何帮助是感激的