2011-11-13 100 views

回答

1

首先安裝Python圖像庫(pip install Pillow

注意:您可能需要將路徑更改爲您的字體文件font_fname

import scipy as sp 
import PIL 
import PIL.Image as Image 
import PIL.ImageDraw as ImageDraw 
import PIL.ImageFont as ImageFont 

font_fname = '/usr/share/fonts/truetype/freefont/FreeSansBold.ttf' 
font_size = 200 
font = ImageFont.truetype(font_fname, font_size) 

h, w = 1080, 1920 
bg_colour = (255, 255, 255) 
bg_image = sp.dot(sp.ones((h,w,3), dtype='uint8'), sp.diag(sp.asarray((bg_colour), dtype='uint8'))) 
image0 = Image.fromarray(bg_image) 
draw = ImageDraw.Draw(image0) 
draw.text((530, 160), "hello world", font=font, fill='rgb(0, 0, 0)') 
image0.save('hello_world.jpg') 
+0

如何添加特殊效果(如陰影,膨脹,噪音等)? – NightFury13