当前位置: 首页>>代码示例>>Python>>正文


Python ImageDraw.line方法代码示例

本文整理汇总了Python中PIL.ImageDraw.line方法的典型用法代码示例。如果您正苦于以下问题:Python ImageDraw.line方法的具体用法?Python ImageDraw.line怎么用?Python ImageDraw.line使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PIL.ImageDraw的用法示例。


在下文中一共展示了ImageDraw.line方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: draw

# 需要导入模块: from PIL import ImageDraw [as 别名]
# 或者: from PIL.ImageDraw import line [as 别名]
 def draw(self, image_draw: ImageDraw):
     image_draw.line((self._coordinates.x - self._diameter, self._coordinates.y - self._diameter,
                      self._coordinates.x + self._diameter, self._coordinates.y + self._diameter),
                     fill=self._color, width=self._linewidth)
     image_draw.line((self._coordinates.x + self._diameter, self._coordinates.y - self._diameter,
                      self._coordinates.x - self._diameter, self._coordinates.y + self._diameter),
                     fill=self._color, width=self._linewidth)
开发者ID:jimrybarski,项目名称:fylm_critic,代码行数:9,代码来源:artist.py

示例2: generate_captcha

# 需要导入模块: from PIL import ImageDraw [as 别名]
# 或者: from PIL.ImageDraw import line [as 别名]
def generate_captcha(request):
    path = '.'
    im = Image.new('RGBA', (200, 50), (0, 0, 0, 0))
    draw = ImageDraw(im)
    number = ''
    margin_left, margin_top = 0, 0
    colnum = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
    i = 0
    while i < 6:
        font_color = '#' + str(random.randint(0,9))
        y = 0
        while y < 5:
            rand = random.choice(colnum)
            font_color = font_color + rand
            y += 1
        rand_x11 = random.randint(0, 100)
        rand_x12 = random.randint(100, 200)
        rand_y11 = random.randint(0, 50)
        rand_y12 = random.randint(0, 50)
        draw.line((rand_x11, rand_y11, rand_x12, rand_y12), fill='#a9a6a6')
        font_rand = str(random.randint(1, 10))
        font_size_rand = random.randint(30, 40)
        font = ImageFont.truetype(path + "fonts/" + font_rand + ".ttf", font_size_rand)
        a = str(random.randint(0, 9))
        draw.text((margin_left, margin_top), a, fill=str(font_color), font=font)
        rand_x11 = random.randint(0, 100)
        rand_x12 = random.randint(100, 200)
        rand_y11 = random.randint(0, 50)
        rand_y12 = random.randint(0, 50)
        draw.line((rand_x11, rand_y11, rand_x12, rand_y12), fill="#a9a6a6")
        margin_left = margin_left + random.randint(20, 35)
        margin_top = random.randint(0, 20)
        i += 1
        number += a
    salt = "[email protected]!SAf*[email protected])[email protected]$1512czvaRV"
    key = md5(str(number + salt)).hexdigest()
    output = StringIO()
    im.save(output, format="PNG")
    contents = output.getvalue().encode("base64").replace("\n", "")
    img_tag = '<img value="' + key + '" src="data:image/png;base64,{0}">'.format(contents)
    output.close()
    return img_tag
开发者ID:lafabo,项目名称:i-love-tutorials,代码行数:44,代码来源:captcha.py


注:本文中的PIL.ImageDraw.line方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。