Python实现将字体转变成图片 使用pygame或ImageFont

import os, time, sys
def p(*x): print(*x)

import numpy as np
import array, random
from pydub import AudioSegment
import pygame
from bson import BSON
import matplotlib.pyplot as plt

from pygame.locals import *

import os
from PIL import Image, ImageFont, ImageDraw

text = u"这是一段测试文本,test 123。"
  
im = Image.new("RGB", (300, 50), (255, 255, 255))
dr = ImageDraw.Draw(im)
font = ImageFont.truetype(os.path.join("fonts", "msyh.ttf"), 25)
 
dr.text((10, 5), text, font=font, fill="#000000")
  
im.show()

p(im)

# pygame.init()
# text = "万硅"
# font = pygame.font.SysFont('Microsoft YaHei', 64)
# ftext = font.render(text, True, (65, 83, 130),(255, 255, 255))
# pygame.image.save(ftext, "test.jpg")

# im = Image.open("test.jpg")
# im.show()


发表于:2014-10-12 16:13:31

原文链接(转载请保留): http://www.multisilicon.com/blog/a24332246.html

友情链接: MICROIC
首页