本文整理汇总了Python中PIL.ImageDraw.text方法的典型用法代码示例。如果您正苦于以下问题:Python ImageDraw.text方法的具体用法?Python ImageDraw.text怎么用?Python ImageDraw.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PIL.ImageDraw
的用法示例。
在下文中一共展示了ImageDraw.text方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PrintText
# 需要导入模块: from PIL import ImageDraw [as 别名]
# 或者: from PIL.ImageDraw import text [as 别名]
def PrintText(self, text):
# led.draw_text2(x-axis, y-axis, whatyouwanttoprint, size) < Understand?
# So led.drawtext2() prints simple text to the OLED display like so:
#text = 'Hello!'
# Create the image to write to the display
# THIS MAY NEED TO CHANGE BASED ON STRING LENGTH!
image = Image.new('1', (128, 64))
draw = ImageDraw(image)
draw.text((0, 0), text, font=ImageFont.load_default(), fill=255)
# Clear the Display
self.led.clear()
self.led.display()
# Write the text-based image to the display
self.led.image(image)
self.led.display()
示例2: generate_captcha
# 需要导入模块: from PIL import ImageDraw [as 别名]
# 或者: from PIL.ImageDraw import text [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
示例3: str
# 需要导入模块: from PIL import ImageDraw [as 别名]
# 或者: from PIL.ImageDraw import text [as 别名]
from PIL import Image, ImageDraw, ImageFont
num = str(5)
img = Image.open('shenle.png')
h, l = img.size
font = ImageFont.truetype('/usr/share/fonts/truetype/droid/DroidSans.ttf', 30)
draw = ImageDraw(img)
draw.text((h*0.8, l*0.2), num, font=font, fill(255, 33, 33))
img.save('shenle5.png', 'png')