本文整理汇总了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)
示例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