python 用PIL画一个python图标

python 用PIL画一个python图标

形状目测差不多

from PIL import Image, ImageColor, ImageDraw, ImageFont

def getPyImage(s=256):
    ratio = s / 256
    def pos(*cord):
        return [int(ratio * x) for x in cord]

    c1 = ImageColor.getcolor('#387eb8ff', 'RGBA')
    c2 = ImageColor.getcolor('#ffe052ff', 'RGBA')
    clear = ImageColor.getcolor('#00000000', 'RGBA')

    def half(color):
        image = Image.new(mode='RGBA', size=pos(256, 256), color=(0, 0, 0, 0))
        draw = ImageDraw.Draw(image)  # 新建画布绘画对象
        draw.chord(pos(66, 0, 190, 55), 180, 0, fill=color)
        draw.rectangle(pos(66, 27.5, 190, 58), fill=color)
        draw.rectangle(pos(128, 27.5, 190, 124), fill=color)

        draw.chord(pos(0, 66, 70, 190), 90, 270, fill=color)
        draw.rectangle(pos(35, 66, 58, 190), fill=color)
        draw.rectangle(pos(35, 66, 190, 124), fill=color)

        draw.rectangle(pos(160, 94, 190, 124), fill=clear)
        draw.ellipse(pos(130, 64, 190, 124),  fill=color)

        draw.rectangle(pos(58, 124, 88, 154), fill=color)
        draw.ellipse(pos(58, 124, 118, 184),  fill=clear)

        draw.ellipse(pos(82, 19, 104, 41), fill=clear)
        return image

    image1 = half(c1)
    image2 = half(c2)
    image2 = image2.rotate(180)

    py_image = Image.alpha_composite(image1, image2)
    return py_image


getPyImage(1024).show()
    
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值