日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 白色怎么表示_python – 如何使用pil使用白色背景(透明?)的round_corner标识?...

發布時間:2025/3/15 python 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 白色怎么表示_python – 如何使用pil使用白色背景(透明?)的round_corner标识?... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我有一個方形徽標,我需要round_corner它,搜索了一段時間,并得到以下代碼“工作”:

def round_corner_jpg(image, radius):

"""generate round corner for image"""

mask = Image.new('RGB', image.size)

#mask = Image.new('RGB', (image.size[0] - radius, image.size[1] - radius))

#mask = Image.new('L', image.size, 255)

draw = aggdraw.Draw(mask)

brush = aggdraw.Brush('black')

width, height = mask.size

draw.rectangle((0,0,width,height), aggdraw.Brush('white'))

#upper-left corner

draw.pieslice((0,0,radius*2, radius*2), 90, 180, None, brush)

#upper-right corner

draw.pieslice((width - radius*2, 0, width, radius*2), 0, 90, None, brush)

#bottom-left corner

draw.pieslice((0, height - radius * 2, radius*2, height),180, 270, None, brush)

#bottom-right corner

draw.pieslice((width - radius * 2, height - radius * 2, width, height), 270, 360, None, brush)

#center rectangle

draw.rectangle((radius, radius, width - radius, height - radius), brush)

#four edge rectangle

draw.rectangle((radius, 0, width - radius, radius), brush)

draw.rectangle((0, radius, radius, height-radius), brush)

draw.rectangle((radius, height-radius, width-radius, height), brush)

draw.rectangle((width-radius, radius, width, height-radius), brush)

draw.flush()

del draw

return ImageChops.add(mask, image)

然后我保存了返回的圖像對象,但它在角落里有白色背景

like this

我怎樣才能擺脫白色背景或使其隱形?

提前謝謝?

編輯:

這是fraxel的代碼,謝謝?

def add_corners(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, "white")

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

if __name__ == '__main__':

im = Image.open('1.jpg')

im = add_corners(im, 100)

im.save('out.png')`

我很抱歉..我需要圖像形狀為橢圓形而不是矩形,I.E.從圖片中寫下來的東西和@fraxel,我仍然可以看到你為我處理的圖片中的白色角落

總結

以上是生活随笔為你收集整理的python 白色怎么表示_python – 如何使用pil使用白色背景(透明?)的round_corner标识?...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。