Merge branch 'master' of https://e.coding.net/ctcdevteam/cma_search
This commit is contained in:
commit
737ce33e21
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.2.12 on 2023-09-04 08:08
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('edu', '0002_auto_20230823_1529'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='certificate',
|
||||||
|
name='字体方案',
|
||||||
|
field=models.PositiveSmallIntegerField(default=1),
|
||||||
|
),
|
||||||
|
]
|
|
@ -17,3 +17,4 @@ class Certificate(CommonADModel):
|
||||||
是否需要集团证书 = models.BooleanField(default=False)
|
是否需要集团证书 = models.BooleanField(default=False)
|
||||||
是否需要北京标研培训合格 = models.BooleanField(default=False)
|
是否需要北京标研培训合格 = models.BooleanField(default=False)
|
||||||
证书地址 = models.CharField(max_length=100, null=True, blank=True)
|
证书地址 = models.CharField(max_length=100, null=True, blank=True)
|
||||||
|
字体方案 = models.PositiveSmallIntegerField(default=1)
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
from PIL import ImageFont, ImageDraw, Image
|
from PIL import ImageFont, ImageDraw, Image
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from apps.edu.models import Certificate
|
from apps.edu.models import Certificate
|
||||||
|
font_dict = {
|
||||||
|
'font_1': "/media/cert/template/weibei.ttf",
|
||||||
|
'font_2': "/media/cert/template/SIMLI.TTF"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def make_img_x(instance: Certificate):
|
def make_img_x(instance: Certificate):
|
||||||
titles = []
|
titles = []
|
||||||
|
@ -12,15 +17,15 @@ def make_img_x(instance: Certificate):
|
||||||
titles.append('质量负责人')
|
titles.append('质量负责人')
|
||||||
if instance.是否最高管理者:
|
if instance.是否最高管理者:
|
||||||
titles.append('最高管理者')
|
titles.append('最高管理者')
|
||||||
instance.证书地址 = make_img(instance.证书编号, instance.姓名, '、'.join(titles))
|
instance.证书地址 = make_img(instance.证书编号, instance.姓名, '、'.join(titles), font_dict[f'font_{instance.字体方案}'])
|
||||||
instance.save()
|
instance.save()
|
||||||
|
|
||||||
def make_img(number, name, title):
|
def make_img(number, name, title, font_name_path):
|
||||||
# 打开底版图片
|
# 打开底版图片
|
||||||
imageFile = settings.BASE_DIR + '/media/cert/template/background.jpg'
|
imageFile = settings.BASE_DIR + '/media/cert/template/background.jpg'
|
||||||
img = Image.open(imageFile)
|
img = Image.open(imageFile)
|
||||||
# 选择字体与大小
|
# 选择字体与大小
|
||||||
font = ImageFont.truetype(settings.BASE_DIR+ "/media/cert/template/weibei.ttf", 155)
|
font = ImageFont.truetype(settings.BASE_DIR+ font_name_path, 155)
|
||||||
font_title = ImageFont.truetype(settings.BASE_DIR + "/media/cert/template/siyuan.otf", 76)
|
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)
|
font_number = ImageFont.truetype(settings.BASE_DIR + "/media/cert/template/timesbd.ttf", 58)
|
||||||
# print(font)
|
# print(font)
|
||||||
|
|
Loading…
Reference in New Issue