def avatar_gen_img(self):
font_size = int(self.size / 10 * 8)
pic_size = self.size
an, is_letter = self.avatar_name()
font = self.zh_font_file_name
if is_letter:
font = self.en_font_file_name
font_size = int(self.size / 10 * 11)
font_file = os.path.abspath(os.path.join(self.font_dir, font))
pygame.init()
f = pygame.font.Font(font_file, font_size)
is_light=self.is_light_color(self.avatar_background_color())
rtext = f.render(an.upper(), True, (0,0,0) if is_light else (255, 255, 255))
# pygame.image.save(rtext, '%s.png' % an)
mode = 'RGBA'
astr = pygame.image.tostring(rtext, 'RGBA')
circle = Image.new("RGBA", (self.size, self.size))
word = Image.frombytes(mode, f.size(an), astr)
word_x = int((pic_size - word.size[0]) / 2)
word_y = int(word_x * 0.9)
if is_letter:
word_y = int((pic_size - word.size[1]) / 2)
draw = ImageDraw.Draw(circle)
draw.ellipse((0, 0, self.size , self.size ),
fill=self.avatar_background_color(), outline=self.avatar_background_color())
draw.point((100, 100), 'red')
r, g, b, a = word.split()
circle.paste(word, (word_x, word_y), a)
sharpness = ImageEnhance.Sharpness(circle)
# circle = sharpness.enhance(7.0)
# im.show()
# circle.show()
# print(circle)
return circle
评论列表
文章目录