44 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
from PIL import ImageFont, ImageDraw, Image
 | 
						|
from django.conf import settings
 | 
						|
 | 
						|
def make_img(number, name, title):
 | 
						|
    # 打开底版图片
 | 
						|
    imageFile =  settings.BASE_DIR +   '/media/cert/template/background.jpg'
 | 
						|
    img = Image.open(imageFile)
 | 
						|
    # 选择字体与大小
 | 
						|
    font = ImageFont.truetype(settings.BASE_DIR+ "/media/cert/template/weibei.ttf", 155)
 | 
						|
    font_title = ImageFont.truetype(settings.BASE_DIR +   "/media/cert/template/siyuan.otf", 76)
 | 
						|
    font_number = ImageFont.truetype(settings.BASE_DIR +   "/media/cert/template/timesbd.ttf", 58)
 | 
						|
    # print(font)
 | 
						|
    # 在图片上添加文字
 | 
						|
    # word = """     
 | 
						|
    # 夜  归  小  朝
 | 
						|
    # 梦  鸟  舟  有  静
 | 
						|
    # 星  清  载  赤  安
 | 
						|
    # 河  风  我  羽  心
 | 
						|
    # 一  同  湖  暮  野
 | 
						|
    # 壶  桨  旋  落
 | 
						|
    # 茶  驻  停  霞
 | 
						|
 | 
						|
    # ldc 2020-07-25
 | 
						|
    # """
 | 
						|
    word_number = number #"CTCZL20230001"
 | 
						|
    word_name = name #"曹前明"
 | 
						|
    word_title = title #"内审员、授权签字人、质量负责人、最高管理者"
 | 
						|
    # width = img.width
 | 
						|
    # height = img.height
 | 
						|
    # # 查看图片宽高
 | 
						|
    # print(width,height)
 | 
						|
    position_number = (1772, 645)
 | 
						|
    position_name = (628, 860)
 | 
						|
    position_title = (900, 1230)
 | 
						|
    color_name = (82, 68, 19)
 | 
						|
    color = (0,0,0)
 | 
						|
    draw = ImageDraw.Draw(img)
 | 
						|
    draw.text(position_name, word_name, color_name, font=font)
 | 
						|
    draw.text(position_title, word_title, color, font=font_title)
 | 
						|
    draw.text(position_number, word_number, color_name, font=font_number)
 | 
						|
    # 保存图片
 | 
						|
    path = f"/media/cert/{number}.jpg"
 | 
						|
    img.save(settings.BASE_DIR +   path)
 | 
						|
    return path |