欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python使用画图函数实现身份证操作

程序员文章站 2023-11-29 11:11:34
画图函数: base_dir = f'{main.BASE_DIR}/quality_management_logic/dataCenter/' self.draw.text((55, self.height * 0.31), self.personName, (0, 0, 0), font=ImageFont.truetype(os.path.join(base_dir, 'msyh.ttc'),24)) #personname应...

画图函数:

   base_dir = f'{main.BASE_DIR}/quality_management_logic/dataCenter/'
        self.draw.text((55, self.height * 0.31), self.personName, (0, 0, 0),
                       font=ImageFont.truetype(os.path.join(base_dir, 'msyh.ttc'),24))  #personname

应用:
# -*- coding: utf-8 -*-
# import random, string
# import datetime
from tkinter import *
import os
from PIL import Image,ImageDraw,ImageFont
from quality_management_logic.commonCenter.Pan import get_advance,yaml_w,month_trans
import main
#保存图片

class GUICard(object):
    def __init__(self):
        get_Advance = get_advance('YUANDING')
        self.personName = str(get_Advance.get('userName')).ljust(15, ' ')
        # self.personName='SHOUXINPASS'.ljust(15, ' ')
        self.fathersName = str(get_Advance.get('fatherName')).ljust(15, ' ')
        self.birthday = get_Advance.get('birthDate')
        self.panID = get_Advance.get('panNo')
        self.common_front_path = f'{main.BASE_DIR}/quality_management_logic/dataCenter/msyh.ttf'
        self.img_path = f'{main.BASE_DIR}/quality_management_logic/dataCenter/pancard_front.png'
        self.img = Image.open(self.img_path)
        self.draw = ImageDraw.Draw(self.img)
        self.width, self.height = self.img.size
    def InPutCard(self,path=f"{main.BASE_DIR}/quality_management_logic/dataCenter/pancard.jpg"):
        base_dir = f'{main.BASE_DIR}/quality_management_logic/dataCenter/'
        self.draw.text((55, self.height * 0.31), self.personName, (0, 0, 0),
                       font=ImageFont.truetype(os.path.join(base_dir, 'msyh.ttc'),24))  #personname
        self.draw.text((55 , self.height * 0.40), self.fathersName, (0, 0, 0),
                       font=ImageFont.truetype(os.path.join(base_dir, 'msyh.ttc'),24))   #fathername
        self.draw.text((self.width * 0.08, self.height * 0.50), self.birthday, (0, 0, 0),
                       font=ImageFont.truetype(os.path.join(base_dir, 'msyh.ttc'),24))   #brithday

        self.draw.text((self.width * 0.08, self.height * 0.63), self.panID, (0, 0, 0),
                       font=ImageFont.truetype(os.path.join(base_dir, 'msyh.ttc'),24))  #panid

        # ImageDraw.Draw(self.img)
        # imageFileSave =f"{main.BASE_DIR}/quality_management_logic/dataCenter/pancard.jpg"
        imageFileSave=path
        self.img.save(imageFileSave)
        # 写入yaml
        self.birthday1 = month_trans(self.birthday)
        ocrData = {"date_of_birth": self.birthday1, "pan_code": self.panID,
                   "pan_img1": "https://in.creditech.biz/image/fi360/0332747ff0385a210a97d702d5cb1d83.jpg",
                   "user_father_name": self.fathersName.strip(), "user_name": self.personName.strip()}
        yaml_w({"ocrData": ocrData, "userName": self.personName.strip(), "panNo": self.panID, "fatherName": self.fathersName.strip(),
                "birthDate": self.birthday})
        return imageFileSave

图:
python使用画图函数实现身份证操作
接入前端:
python使用画图函数实现身份证操作
python使用画图函数实现身份证操作

本文地址:https://blog.csdn.net/kairui_guxiaobai/article/details/107067972