Esempio n. 1
0
    def put_txt_img(self,
                    img,
                    t,
                    total_dis,
                    xy,
                    dis_line,
                    fill,
                    font_name,
                    font_size,
                    addSPC='None'):

        fontInput = self.fonts(font_name, font_size)
        if addSPC == 'add_2spaces':
            ind = 'yes'
        else:
            ind = 'no'

        # txt=self.split_txt(total_dis,font_size,t,Indent='no')
        txt, p_num = composing.split_txt_Chn_eng(total_dis,
                                                 font_size,
                                                 t,
                                                 Indent=ind)

        # font_sig = self.fonts('丁永康硬笔楷书',40)
        draw = ImageDraw.Draw(img)
        # logging.info(txt)
        n = 0
        for t in txt:
            m = 0
            for tt in t:
                x, y = xy[0], xy[1] + (font_size + dis_line) * n
                if addSPC == 'add_2spaces':  #首行缩进
                    if m == 0:
                        # tt='  '+tt #首先前面加上两个空格
                        logging.info('字数:' + str(len(tt)) + ',坐标:' + str(x) +
                                     ',' + str(y))
                        logging.info(tt)
                        draw.text((x - font_size * 0.2, y),
                                  tt,
                                  fill=fill,
                                  font=fontInput)
                    else:
                        logging.info('字数:' + str(len(tt)) + ',坐标:' + str(x) +
                                     ',' + str(y))
                        logging.info(tt)
                        draw.text((x, y), tt, fill=fill, font=fontInput)
                else:
                    logging.info('字数:' + str(len(tt)) + ',坐标:' + str(x) + ',' +
                                 str(y))
                    logging.info(tt)
                    draw.text((x, y), tt, fill=fill, font=fontInput)

                m += 1
                n += 1
Esempio n. 2
0
    def PosterDraw(self, crs_nameInput, dateInput, TeacherSig='阿晓老师'):
        crs_name = crs_nameInput[4:]
        crs_code = crs_nameInput[0:4]

        def basic_para():
            print('正在初始化参数……', end='')
            picWid = self.picWid
            r = 0.75
            picX1, picX3 = 10, 10
            picX2, picX4 = picX1 + picWid + 20, picX1 + picWid + 20
            picY1, picY2 = 720, 720
            picY3, picY4 = picY1 + picWid * r + 20, picY1 + picWid * r + 20

            pic0 = pic_xy(picWid, int(picWid * r), 440, 290)  #标题图
            pic1 = pic_xy(picWid, int(picWid * r), picX1, picY1)  #照片一
            pic2 = pic_xy(picWid, int(picWid * r), picX2, picY2)  #照片二
            pic3 = pic_xy(picWid, int(picWid * r), picX3, picY3)  #照片三
            pic4 = pic_xy(picWid, int(picWid * r), picX4, picY4)  #照片四
            print('完成')

            return [
                picWid, picX1, picX2, picX3, picX4, picY1, picY2, picY3, picY4,
                pic0, pic1, pic2, pic3, pic4
            ]

        def sortPics(files):
            newfiles = {}
            for fn in files:
                if fn[-3:].lower() == 'jpg':
                    with open(fn, 'rb') as fd:
                        tag = exifread.process_file(fd)
                        t = str(tag['EXIF DateTimeOriginal']).replace(
                            ':', '-', 2)
                        if t in newfiles.keys():
                            t = t[0:-2] + str(int(t[-2:]) + 1).zfill(2)
                            newfiles[t] = fn
                        else:
                            newfiles[t] = fn
                        # print('exifInfo:',t,fn)
            newList = []
            for i in sorted(newfiles):
                newList.append(newfiles[i])
            return newList

        def read_excel():
            print('正在读取学员和课程信息……', end='')
            infos=WashData.comments_after_class(crs_name_input=crs_nameInput,weekday=self.weekday, \
                                                crs_list=self.crsList,crs_student=self.crsStudent, \
                                                tch_cmt=self.eachStd)
            print('完成')
            return infos

        def pic_xy(picWid, picHig, x0, y0):
            #白色矩形
            recX0 = x0
            recY0 = y0
            recX1 = x0 + picWid + 10
            recY1 = y0 + picHig + 10

            #照片
            picX0 = recX0 + 5
            picY0 = recY0 + 5
            picX1 = picX0 + picWid
            picY1 = picY0 + picHig

            return [[int(recX0),
                     int(recY0),
                     int(recX1),
                     int(recY1)],
                    [int(picX0),
                     int(picY0),
                     int(picX1),
                     int(picY1)]]

        def color_list(list_num='202002'):
            colors_202002 = {
                'title_bg': '#FF9E11',  #乐高机器人课
                'name': '#FFFFFF',  # 姓名 年龄
                'crs': '#00b578',  #课程
                'pics': '#f7f7f7',  #照片大框
                'pics_box': '#ffffff',  #照片相框
                'pic01': '#ffffff',
                'pic02': '#ffffff',
                'pic03': '#ffffff',
                'pic04': '#ffffff',
                'comments': '#00bde3',  #老师评语
                'logo': '#ffffff',  #logo
                't_title_ke1': '#ffffff',
                't_title_xue': '#ffffff',
                't_title_ji': '#ffffff',
                't_title_qi': '#ffffff',
                't_title_ren': '#ffffff',
                't_title_ke4': '#ffffff',
                't_name': '#00b578',  #姓名
                't_kdgtn': '#00b578',  #幼儿园
                't_class': '#00b578',  #班级
                't_crs': '#FFE340',  #课程名称
                't_diff': '#ffffff',  #难度
                't_tool': '#ffffff',  #教具
                't_knlg': '#ffffff',  #知识点
                't_date': '#ffffff',  #日期
                't_tch_cmt': '#ffffff',  #老师评语
                't_tch_sig': '#ffffff',  #签名
                't_bottom': '#656564'  #二维码文字
            }
            colors_202101 = {
                'title_bg': '#f7f3c3',  #乐高机器人课
                'name': '#FFFFFF',  # 姓名 年龄
                'crs': '#f1f9ee',  #课程
                'pics': '#f7f7f7',  #照片大框
                'pics_box': '#ffffff',  #照片相框
                'pic01': '#ffffff',
                'pic02': '#ffffff',
                'pic03': '#ffffff',
                'pic04': '#ffffff',
                'comments': '#f9f9f9',  #老师评语
                'logo': '#ffffff',  #logo
                't_title_ke1': '#009ce6',
                't_title_xue': '#33b171',
                't_title_ji': '#ef9c10',
                't_title_qi': '#8bbe19',
                't_title_ren': '#dc9ee7',
                't_title_ke4': '#b18046',
                't_name': '#99633f',  #姓名
                't_kdgtn': '#99633f',  #幼儿园
                't_class': '#99633f',  #班级
                't_crs': '#37a751',  #课程名称
                't_diff': '#8b988e',  #难度
                't_tool': '#8b988e',  #教具
                't_knlg': '#8b988e',  #知识点
                't_date': '#8b988e',  #日期
                't_tch_cmt': '#795022',  #老师评语
                't_tch_sig': '#795022',  #签名
                't_bottom': '#656564'  #二维码文字
            }

            out = eval('colors_' + list_num)

            return out

        def basic_bg(num):
            color = color_list('202101')
            s1 = 100
            s2 = 140
            s3 = 450
            s4 = 700
            self.s4 = s4
            s5 = (self.comment_font_size +
                  self.comment_dis_line) * self.para_num + 120
            self.s5 = s5
            s6 = 200
            self.s6 = s6
            sprt = 5
            total_len = s1 + s2 + s3 + s4 + s5 + s6 + sprt * 5

            y1 = s1

            y2 = y1 + sprt
            y2_2 = y2 + s2

            y3 = y2_2 + sprt
            y3_2 = y3 + s3

            y4 = y3_2 + sprt
            y4_2 = y4 + s4
            self.y4 = y4
            self.y4_2 = y4_2

            y5 = y4_2 + sprt
            y5_2 = y5 + s5
            self.y5 = y5
            self.y5_2 = y5_2

            y6 = y5_2 + sprt
            y6_2 = y6 + s6
            self.y6 = y6
            self.y6_2 = y6_2

            if num == 4:
                img = Image.new("RGB", (900, total_len), (255, 255, 255))
                draw = ImageDraw.Draw(img)
                draw.rectangle([(0, 0), (900, y1)],
                               fill=color['title_bg'])  #乐高机器人课
                draw.rectangle([(0, y2), (900, y2_2)],
                               fill=color['name'])  # 姓名 年龄
                draw.rectangle([(0, y3), (900, y3_2)], fill=color['crs'])  # 课程
                draw.rectangle([(0, y4), (900, y4_2)],
                               fill=color['pics'])  # 照片
                draw.rectangle([(0, y5), (900, y5_2)],
                               fill=color['comments'])  # 能力测评
                draw.rectangle([(0, y6), (900, y6_2)],
                               fill=color['logo'])  # logo

                draw.rectangle([(pic0[0][0], pic0[0][1]),
                                (pic0[0][2], pic0[0][3])],
                               fill=color['pics_box'])  #相框_课程
                draw.rectangle([(pic1[0][0], pic1[0][1]),
                                (pic1[0][2], pic1[0][3])],
                               fill=color['pic01'])  #相框_1
                draw.rectangle([(pic2[0][0], pic2[0][1]),
                                (pic2[0][2], pic2[0][3])],
                               fill=color['pic02'])  #相框_2
                draw.rectangle([(pic3[0][0], pic3[0][1]),
                                (pic3[0][2], pic3[0][3])],
                               fill=color['pic03'])  #相框_3
                draw.rectangle([(pic4[0][0], pic4[0][1]),
                                (pic4[0][2], pic4[0][3])],
                               fill=color['pic04'])  #相框_4
            elif num == 2:
                img = Image.new("RGB", (900, int(total_len - s4 / 2)),
                                (255, 255, 255))
                draw = ImageDraw.Draw(img)
                draw.rectangle([(0, 0), (900, y1)],
                               fill=color['title_bg'])  #乐高机器人课
                draw.rectangle([(0, y2), (900, y2_2)],
                               fill=color['name'])  # 姓名 年龄
                draw.rectangle([(0, y3), (900, y3_2)], fill=color['crs'])  # 课程
                draw.rectangle([(0, y4), (900, y4_2 - s4 / 2)],
                               fill=color['pics'])  # 照片
                draw.rectangle([(0, y5 - s4 / 2), (900, y5_2 - s4 / 2)],
                               fill=color['comments'])  # 能力测评
                draw.rectangle([(0, y6 - s4 / 2), (900, y6_2 - s4 / 2)],
                               fill=color['logo'])  # logo

                draw.rectangle([(pic0[0][0], pic0[0][1]),
                                (pic0[0][2], pic0[0][3])],
                               fill=color['pics_box'])  #相框_课程
                draw.rectangle([(pic1[0][0], pic1[0][1]),
                                (pic1[0][2], pic1[0][3])],
                               fill=color['pic01'])  #相框_1
                draw.rectangle([(pic2[0][0], pic2[0][1]),
                                (pic2[0][2], pic2[0][3])],
                               fill=color['pic02'])  #相框_2
                # draw.rectangle([(pic3[0][0],pic3[0][1]),(pic3[0][2],pic3[0][3])],fill=color['pic03']) #相框_3
                # draw.rectangle([(pic4[0][0],pic4[0][1]),(pic4[0][2],pic4[0][3])],fill=color['pic04']) #相框_4

            return img

        def pick_pics(stdName):
            # print('stdname:',stdName)
            pic_title_addr = os.path.join(self.ConsDir, crs_nameInput,
                                          crs_name + '.jpg')  #课程的标题图

            ptn = '-.*-'
            pics_for_crs = []

            for root, dirs, files in os.walk(
                    os.path.join(self.picStdDir, stdName)):  #学员的照片
                for file in files:
                    try:
                        if re.findall(ptn, file)[0][1:-1] == crs_nameInput:
                            PicTags = readConfig.code_to_str(
                                iptcinfo3.IPTCInfo(
                                    os.path.join(self.picStdDir, stdName,
                                                 file)))
                            # print('tags:',PicTags)
                            if '每周课程4+' in PicTags:
                                pics_for_crs.append(
                                    os.path.join(self.picStdDir, stdName,
                                                 file))
                    except:
                        pass
            # print(pics_for_crs)
            # pics=pick_pics(stdName)
            if len(pics_for_crs) > 3:
                num = 4
            else:
                num = 2

            # print('number:',num)
            pics_stds_addrs = random.sample(pics_for_crs, num)

            # print(pics_stds_addrs)
            sorted_pics_stds_addrs = sortPics(pics_stds_addrs)
            pics = [pic_title_addr]
            pics.extend(sorted_pics_stds_addrs)
            return pics

        def putImg(img, stdName):
            print('    正在置入图片……', end='')
            pics = pick_pics(stdName)

            if self.bg_img_num > 3:
                f_crs, f_01, f_02, f_03, f_04 = pics

                pic_crs = self.pic_resize(Image.open(f_crs), picWid)
                pic_01 = self.pic_resize(Image.open(f_01), picWid)
                pic_02 = self.pic_resize(Image.open(f_02), picWid)
                pic_03 = self.pic_resize(Image.open(f_03), picWid)
                pic_04 = self.pic_resize(Image.open(f_04), picWid)
                _pic_logo = Image.open(
                    'I:\\大智小超\\公共素材\\图片类\\大智小超新logo.png').convert('RGBA')
                pic_logo = _pic_logo.resize((350, int(350 / 2.76)))
                r, g, b, a = pic_logo.split()

                _pic_qrcode = Image.open(
                    'I:\\大智小超\\公共素材\\图片类\\大智小超视频号二维码2.png')
                pic_qrcode = _pic_qrcode.resize((130, 130))

                logging.info('照片尺寸:' + ','.join(self.sstr(pic_crs.size)))
                img.paste(pic_crs, (pic0[1][0], pic0[1][1]))
                img.paste(pic_01, (pic1[1][0], pic1[1][1]))
                img.paste(pic_02, (pic2[1][0], pic2[1][1]))
                img.paste(pic_03, (pic3[1][0], pic3[1][1]))
                img.paste(pic_04, (pic4[1][0], pic4[1][1]))
                img.paste(pic_logo,
                          (50, int(self.y5_2 + self.s6 / 2 - 350 / 2.76 / 2)),
                          mask=a)
                img.paste(pic_qrcode,
                          (700, int(self.y5_2 + self.s6 / 2 - 130 / 2)))
            else:
                f_crs, f_01, f_02 = pics

                pic_crs = self.pic_resize(Image.open(f_crs), picWid)
                pic_01 = self.pic_resize(Image.open(f_01), picWid)
                pic_02 = self.pic_resize(Image.open(f_02), picWid)

                _pic_logo = Image.open(
                    'I:\\大智小超\\公共素材\\图片类\\大智小超新logo.png').convert('RGBA')
                pic_logo = _pic_logo.resize((350, int(350 / 2.76)))
                r, g, b, a = pic_logo.split()

                _pic_qrcode = Image.open(
                    'I:\\大智小超\\公共素材\\图片类\\大智小超视频号二维码2.png')
                pic_qrcode = _pic_qrcode.resize((130, 130))

                logging.info('照片尺寸:' + ','.join(self.sstr(pic_crs.size)))
                img.paste(pic_crs, (pic0[1][0], pic0[1][1]))
                img.paste(pic_01, (pic1[1][0], pic1[1][1]))
                img.paste(pic_02, (pic2[1][0], pic2[1][1]))

                img.paste(pic_logo, (50, int(self.y5_2 - self.s4 / 2) +
                                     int(self.s6 / 2 - 350 / 2.76 / 2)),
                          mask=a)
                img.paste(pic_qrcode, (700, int(self.y5_2 - self.s4 / 2) +
                                       int(self.s6 / 2 - 130 / 2)))

            print('完成')

        def expScript(name_input):
            stdname = name_input
            nickname = teacherCmt[teacherCmt['学生姓名'] ==
                                  stdname]['昵称'].values.tolist()[0]
            teacherCmtTxt = teacherCmt[teacherCmt['学生姓名'] == stdname][
                str(dateInput) + '-' + crs_nameInput].values.tolist()[0]
            prsTxt = random.choice(self.PraiseTxt)
            if teacherCmtTxt != '-':
                script = stdname + '在“' + crs_info[0] + '”这节课中,' + crs_info[
                    2] + '\n' + teacherCmtTxt
            else:
                script = stdname + '在“' + crs_info[0] + '”这节课中,' + crs_info[
                    2] + '\n' + prsTxt

            if '#' in script:
                script = script.replace('#', stdname)
            if '$' in script:
                if nickname == '-':
                    nickname = stdname
                script = script.replace('$', nickname)

            return script

        def putTxt(img, stdName, stdAge, KdgtName, ClassName):
            print('    正在置入文本……', end='')
            color = color_list('202101')
            draw = ImageDraw.Draw(img)

            draw.text((170, 5),
                      '科',
                      fill=color['t_title_ke1'],
                      font=self.fonts('汉仪超级战甲', 75))  #大题目
            draw.text((270, 5),
                      '学',
                      fill=color['t_title_xue'],
                      font=self.fonts('汉仪超级战甲', 75))  #大题目
            draw.text((370, 5),
                      '机',
                      fill=color['t_title_ji'],
                      font=self.fonts('汉仪超级战甲', 75))  #大题目
            draw.text((470, 5),
                      '器',
                      fill=color['t_title_qi'],
                      font=self.fonts('汉仪超级战甲', 75))  #大题目
            draw.text((570, 5),
                      '人',
                      fill=color['t_title_ren'],
                      font=self.fonts('汉仪超级战甲', 75))  #大题目
            draw.text((670, 5),
                      '课',
                      fill=color['t_title_ke4'],
                      font=self.fonts('汉仪超级战甲', 75))  #大题目
            draw.text((350, 120),
                      stdName,
                      fill=color['t_name'],
                      font=self.fonts('汉仪心海行楷w', 60))  #姓名
            # draw.text((530,160), str(stdAge)+'岁', fill = '#6AB34A',font=self.fonts('微软雅黑',60))  #年龄
            draw.text((280, 200),
                      KdgtName,
                      fill=color['t_kdgtn'],
                      font=self.fonts('杨任东竹石体', 33))  #幼儿园
            draw.text((460, 200),
                      ClassName,
                      fill=color['t_class'],
                      font=self.fonts('杨任东竹石体', 33))  #班级

            draw.text((50, 290),
                      '• ' + crs_info[0] + ' •',
                      fill=color['t_crs'],
                      font=self.fonts('华康海报体W12(p)', 40))  #课程名称
            draw.text((50, 360),
                      '难度:' + crs_info[3],
                      fill=color['t_diff'],
                      font=self.fonts('汉仪锐智w', 25))  #难度
            draw.text((530, 630),
                      '使用教具:' + crs_info[4],
                      fill=color['t_tool'],
                      font=self.fonts('微软雅黑', 22))  #教具

            self.put_txt_img(img,
                             crs_info[1],
                             450, [25, 420],
                             25,
                             fill=color['t_knlg'],
                             font_name='汉仪锐智w',
                             font_size=28)  #知识点

            date_txt = '-'.join(
                [str(dateInput)[0:4],
                 str(dateInput)[4:6],
                 str(dateInput)[6:]])
            draw.text((100, 630),
                      date_txt,
                      fill=color['t_date'],
                      font=self.fonts('汉仪心海行楷w', 35))  #日期

            # draw.text((50,1490), '能力测评', fill = '#6AB34A',font=font_2)  #能力测评
            # draw.text((50,1560), 'XX力', fill = '#6AB34A',font=font_3)  #XX力
            # draw.text((50,1610), 'XX力', fill = '#6AB34A',font=font_3)  #XX力
            # draw.text((50,1660), 'XX力', fill = '#6AB34A',font=font_3)  #XX力
            # draw.text((50,1710), 'XX力', fill = '#6AB34A',font=font_3)  #XX力
            script = expScript(stdName)
            if self.bg_img_num > 3:
                self.put_txt_img(img,
                                 script,
                                 780, [60, 1440],
                                 20,
                                 fill=color['t_tch_cmt'],
                                 font_name='丁永康硬笔楷书',
                                 font_size=36,
                                 addSPC='add_2spaces')  #老师评语

                draw.text((650, int(self.y5_2 - 45 * 2 + 45 / 2)),
                          TeacherSig,
                          fill=color['t_tch_sig'],
                          font=self.fonts('丁永康硬笔楷书', 45))  #签名

                draw.text((500, int(self.y5_2 + self.s6 / 2 - 30)),
                          '长按二维码 → \n关注视频号 →',
                          fill=color['t_bottom'],
                          font=self.fonts('微软雅黑', 30))
            else:
                self.put_txt_img(img,
                                 script,
                                 780, [60, 1100],
                                 20,
                                 fill=color['t_tch_cmt'],
                                 font_name='丁永康硬笔楷书',
                                 font_size=36,
                                 addSPC='add_2spaces')  #老师评语

                draw.text(
                    (650, int(self.y5_2 - self.s4 / 2 - 45 * 2 + 45 / 2)),
                    TeacherSig,
                    fill=color['t_tch_sig'],
                    font=self.fonts('丁永康硬笔楷书', 45))  #签名

                draw.text(
                    (500,
                     int(self.y5_2 - self.s4 / 2) + int(self.s6 / 2 - 30)),
                    '长按二维码 → \n关注视频号 →',
                    fill=color['t_bottom'],
                    font=self.fonts('微软雅黑', 30))

            print('完成')

        para = basic_para()

        picWid,picX1,picX2,picX3,picX4,picY1,picY2,picY3,picY4,pic0,pic1,pic2,pic3,pic4= \
        para[0],para[1],para[2],para[3],para[4],para[5],para[6],para[7],para[8],para[9],para[10],para[11],para[12],para[13]

        INFO = read_excel()
        std_list, crs_info, teacherCmt = INFO['std_list'], INFO[
            'crs_info'], INFO['tch_cmt']

        for std in std_list:
            print('正在处理 {} 的图片:'.format(std[3]))
            # img=basic_bg()
            KdgtName, ClassName, stdPY, stdName, stdAge = std[0], std[1], std[
                2], std[3], '-'
            totalTxt = expScript(stdName)
            self.allTxt, self.para_num = composing.split_txt_Chn_eng(
                wid=780,
                font_size=self.comment_font_size,
                txt_input=totalTxt,
                Indent='yes')

            self.bg_img_num = len(pick_pics(std[2] + std[3]))
            if self.bg_img_num > 3:
                img = basic_bg(4)
            else:
                img = basic_bg(2)

            putImg(img, stdPY + stdName)
            putTxt(img, stdName, stdAge, KdgtName, ClassName)

            print('正在保存 {} 的图片……'.format(std[3]), end='')
            if not os.path.exists(
                    os.path.join(self.bg,
                                 str(dateInput) + '-' + crs_nameInput)):
                os.mkdir(
                    os.path.join(self.bg,
                                 str(dateInput) + '-' + crs_nameInput))

            img.save(
                os.path.join(
                    self.bg,
                    str(dateInput) + '-' + crs_nameInput, std[2] + stdName +
                    '-' + str(dateInput) + '-' + crs_nameInput + '.jpg'))
            print('完成')
            # img.show()

        print('\n全部完成,保存文件夹:{} 下面的学生文件名'.format(self.bg))
Esempio n. 3
0
        def ht_cal():
            txt = txts()

            wide = 720
            ht_title = 220
            ht_small_title = 100
            ht_book = 300
            ht_bottom = 300
            ht_gap = 10

            ftsize_small_title = 36
            ftsize_behavior = 30
            dat_behavior = composing.split_txt_Chn_eng(
                wid=700,
                font_size=ftsize_behavior,
                txt_input=txt['behavior'],
                Indent='no')
            txt_behavior = dat_behavior[0]
            ht_behavior = int(dat_behavior[1] * ftsize_behavior * 2.5)

            ftsize_analysis = 30
            dat_analysis = composing.split_txt_Chn_eng(
                wid=700,
                font_size=ftsize_analysis,
                txt_input=txt['analysis'],
                Indent='no')
            txt_analysis = dat_analysis[0]
            ht_analysis = int(dat_analysis[1] * ftsize_analysis * 2.3)

            ftsize_exp = 30
            dat_exp = composing.split_txt_Chn_eng(wid=700,
                                                  font_size=ftsize_exp,
                                                  txt_input=txt['exp'],
                                                  Indent='no')
            txt_exp = dat_exp[0]
            ht_exp = int(dat_exp[1] * ftsize_exp * 2.2)
            ht_exp += 300

            total_ht = ht_title + ht_small_title + ht_behavior + ht_book + ht_analysis + ht_exp + ht_bottom + ht_gap * 6

            ht = {
                'wide': {
                    'total_wt': wide,
                    'total': wide,
                    'small_title': 650,
                    'behavior': 650,
                    'book': 650,
                    'analysis': 650,
                    'exp': 650,
                    'bottom': wide
                },
                'ht': {
                    'total_ht': total_ht,
                    'bg_title': ht_title,
                    'bg_small_title': ht_small_title,
                    'bg_behavior': ht_behavior,
                    'bg_book': ht_book,
                    'bg_analysis': ht_analysis,
                    'bg_exp': ht_exp,
                    'bg_bottom': ht_bottom,
                    'gap': ht_gap
                },
                'ftsize': {
                    'small_title': ftsize_small_title,
                    'behavior': ftsize_behavior,
                    'exp': ftsize_exp,
                    'analysis': ftsize_analysis
                },
                'indent_small_box': 30
            }

            return {'ht': ht, 'txt': txt}
Esempio n. 4
0
    def exp_poster(self,
                   std_name='韦宇浠',
                   start_date='20200930',
                   end_date='20210121',
                   weekday='2',
                   term='2020秋',
                   tch_name='阿晓老师'):
        info = self.draw_std_term_crs(std_name=std_name,
                                      start_date=start_date,
                                      end_date=end_date,
                                      weekday=weekday)
        total_crs = info['total_crs']
        total_crs.dropna(inplace=True)
        std_crs = info['std_crs']
        std_crs.dropna(inplace=True)
        std_info = info['std_info']

        #学期课程总数
        total_crs_num = total_crs.shape[0]
        #格子的行数
        if total_crs_num / 4 == total_crs_num // 4:
            crs_lines = total_crs_num // 4
        else:
            crs_lines = total_crs_num // 4 + 1

        #所有课程格子的总高度
        ht_crs = (170 + 14) * crs_lines

        #学生基本信息
        std_school = std_info['机构'].values[0]
        std_class = std_info['班级'].values[0]

        comments = WashData.std_feedback(std_name=std_name,
                                         xls=self.feedback_xls,
                                         weekday=2)['df_term_comment']
        #学生学期末评语
        comments_for_std = comments[comments['姓名'] == std_name][
            term + '学期总结'].values.tolist()[0].replace('#', std_name)
        std_crs_num = std_crs.shape[0]
        if total_crs_num == std_crs_num:
            std_crs_num_txt = '{0}同学在上一阶段的{1}节科学机器人课中,完成了全部课程的学习!'.format(
                std_name, total_crs_num)
        else:
            std_crs_num_txt = '{0}同学在上一阶段的{1}节科学机器人课中,完成了{2}节课的学习,请假{3}节。'.format(
                std_name, total_crs_num, std_crs_num,
                total_crs_num - std_crs_num)
        comments_for_std = std_crs_num_txt + '\n' + comments_for_std
        font_size_cmt = 30
        prgh_nums = composing.split_txt_Chn_eng(wid=636,
                                                font_size=font_size_cmt,
                                                txt_input=comments_for_std)[1]
        #评语标题高度
        ht_cmt_title = 60
        #评语高度
        ht_prgh = font_size_cmt * 1.5 * (prgh_nums + 4)

        ht_title = 110
        ht_std = 100
        ht_bottom = 210
        gap_0 = 12
        gap_1 = 13

        y_std_1 = 120
        y_std_2 = y_std_1 + 100

        blocks = [ht_title, ht_std, ht_crs, ht_cmt_title, ht_prgh, ht_bottom]
        #计算总的高度
        ht_total_bg = int(sum(blocks) + gap_0 * 4 + gap_1 * (prgh_nums - 1))

        #课程标题坐标
        y_crs_title = y_std_2 + gap_0 + 80

        #课程格最左上角坐标
        y_left_up = y_crs_title + gap_0

        def draw_bg():
            bg = Image.new('RGBA', (720, ht_total_bg), '#F3F9E4')
            draw = ImageDraw.Draw(bg)
            #白底
            draw.rectangle([(13, 110), (707, ht_total_bg - 25)],
                           fill='#FFFFFF')
            #名字绿底
            draw.rectangle([(36, y_std_1), (250, y_std_2)], fill='#F3F9E4')
            draw.rectangle([(36, y_std_2), (684, y_std_2 + 2)], fill='#F3F9E4')

            return bg

        def crs_pic(total_crs=total_crs, std_crs=std_crs, odr=0):
            wid_crs, ht_crs = 150, 170

            #学生上过的课程和总课程的差集
            sub_set = total_crs.copy()
            sub_set = sub_set.append(std_crs)
            sub_set = sub_set.append(std_crs)
            sub_set.drop_duplicates(subset=['课程名称'], keep=False, inplace=True)

            crs_bg = Image.new('RGB', (wid_crs, ht_crs), '#F3F3E4')
            crs_name = total_crs.iloc[odr, :]['课程名称']
            crs_date = total_crs.iloc[odr, :]['上课日期']
            crs_pic = Image.open(
                os.path.join(self.design_dir, crs_name, crs_name[4:] + '.jpg'))
            crs_pic = crs_pic.crop((560, 0, 1280, 720)).resize((110, 110))
            crs_bg.paste(crs_pic, (20, 6))
            draw = ImageDraw.Draw(crs_bg)
            ft_size = 19
            x_txt = int((150 - len(crs_name[4:]) * ft_size) / 2 + 3)

            draw.text((x_txt, 122),
                      crs_name[4:],
                      fill='#8fc31f',
                      font=self.font('方正韵动粗黑简', ft_size))  #课程名称

            #判断是否有不上的课,如有,变灰
            if crs_name not in sub_set['课程名称'].values:
                draw.text((35, 148),
                          str(crs_date)[:11],
                          fill='#8fc31f',
                          font=self.font('方正韵动粗黑简', 12))  #课程日期
            else:
                draw.text((35, 148),
                          '---------',
                          fill='#8fc31f',
                          font=self.font('方正韵动粗黑简', 12))  #课程日期

                crs_bg = ImageEnhance.Brightness(crs_bg).enhance(1.4)
                crs_bg = crs_bg.convert('L')

            # crs_bg.show()
            return crs_bg

        def draw_crs():
            #使用并改变母函数的变量
            nonlocal y_left_up
            bg = draw_bg()
            wid_crs, ht_crs = 150, 170

            draw = ImageDraw.Draw(bg)
            #分隔线

            draw.rectangle([(36, y_crs_title), (684, y_crs_title + 2)],
                           fill='#F3F3E4')

            cnt = 0
            for i in range(crs_lines):
                x_begin = 40
                for j in range(4):
                    if cnt < total_crs_num:
                        crs_block = crs_pic(total_crs=total_crs,
                                            std_crs=std_crs,
                                            odr=cnt)
                        bg.paste(crs_block, (x_begin, y_left_up))
                        x_begin = x_begin + wid_crs + 13
                        cnt += 1
                y_left_up = y_left_up + ht_crs + gap_1

            #分隔线
            draw.rectangle([(36, y_left_up + gap_0),
                            (684, y_left_up + gap_0 + 2)],
                           fill='#F3F3E4')
            #评语绿底
            y_cmt_bg = y_left_up + gap_0 + ht_cmt_title + ht_prgh + 10
            draw.rectangle([(36, y_left_up + gap_0 + ht_cmt_title + 10),
                            (684, y_cmt_bg)],
                           fill='#F3F3E4')

            #二维码,logo
            _pic_logo = Image.open(
                'I:\\大智小超\\公共素材\\图片类\\大智小超新logo.png').convert('RGBA')
            pic_logo = _pic_logo.resize((210, int(210 / 2.76)))
            r, g, b, a = pic_logo.split()

            y_logo = ht_total_bg - 130

            _pic_qrcode = Image.open('I:\\大智小超\\公共素材\\图片类\\大智小超视频号二维码2.png')
            pic_qrcode = _pic_qrcode.resize((100, 100))

            bg.paste(pic_logo, (40, int(y_logo + 10)), mask=a)
            bg.paste(pic_qrcode, (580, int(y_logo)))

            #文字部分
            #标题
            draw.text((130, 5),
                      '科学机器人课',
                      fill='#8fc31f',
                      font=self.font('汉仪超级战甲', 78))
            #姓名班级
            draw.text((60, 142),
                      std_name,
                      fill='#F8B62D',
                      font=self.font('汉仪字酷堂义山楷w', 60))
            draw.text((400, 182),
                      std_school + ' ' + std_class,
                      fill='#6C8466',
                      font=self.font('汉仪字酷堂义山楷w', 30))
            draw.text((45, y_crs_title - 52),
                      '点亮的课程',
                      fill='#8fc31f',
                      font=self.font('鸿蒙印品', 35))
            draw.text((45, y_left_up + gap_0 + 20),
                      '学期评语',
                      fill='#8fc31f',
                      font=self.font('鸿蒙印品', 35))

            #评语
            composing.put_txt_img(draw=draw,tt=comments_for_std,total_dis=628, \
                                  xy=[45,y_left_up+gap_0+110],dis_line=20,fill='#595757', \
                                  font_name='丁永康硬笔楷书',font_size=font_size_cmt,addSPC="add_2spaces")

            draw.text((520, y_cmt_bg - 46),
                      tch_name,
                      fill='#595757',
                      font=self.font('丁永康硬笔楷书', 35))

            draw.text((380, y_logo + 10),
                      '长按二维码 → \n关注视频号 →',
                      fill='#8E9184',
                      font=self.font('微软雅黑', 25))

            bg.show()
            # bg=bg.convert('RGB')
            # bg.save('e:/temp/kkkk2.jpg',quality=90)

        draw_crs()
Esempio n. 5
0
    def PosterDraw(self, crs_nameInput, dateInput, TeacherSig='阿晓老师'):
        crs_name = crs_nameInput[4:]
        crs_code = crs_nameInput[0:4]

        def basic_para():
            print('正在初始化参数……', end='')
            picWid = self.picWid
            r = 0.75
            picX1, picX3 = 10, 10
            picX2, picX4 = picX1 + picWid + 20, picX1 + picWid + 20
            picY1, picY2 = 720, 720
            picY3, picY4 = picY1 + picWid * r + 20, picY1 + picWid * r + 20

            pic0 = pic_xy(picWid, int(picWid * r), 440, 290)  #标题图
            pic1 = pic_xy(picWid, int(picWid * r), picX1, picY1)  #照片一
            pic2 = pic_xy(picWid, int(picWid * r), picX2, picY2)  #照片二
            pic3 = pic_xy(picWid, int(picWid * r), picX3, picY3)  #照片三
            pic4 = pic_xy(picWid, int(picWid * r), picX4, picY4)  #照片四
            print('完成')

            return [
                picWid, picX1, picX2, picX3, picX4, picY1, picY2, picY3, picY4,
                pic0, pic1, pic2, pic3, pic4
            ]

        def sortPics(files):
            newfiles = {}
            for fn in files:
                if fn[-3:].lower() == 'jpg':
                    with open(fn, 'rb') as fd:
                        tag = exifread.process_file(fd)
                        t = str(tag['EXIF DateTimeOriginal']).replace(
                            ':', '-', 2)
                        if t in newfiles.keys():
                            t = t[0:-2] + str(int(t[-2:]) + 1).zfill(2)
                            newfiles[t] = fn
                        else:
                            newfiles[t] = fn
                        # print('exifInfo:',t,fn)
            newList = []
            for i in sorted(newfiles):
                newList.append(newfiles[i])
            return newList

        def read_excel():
            print('正在读取学员和课程信息……', end='')
            infos=WashData.comments_after_class(crs_name_input=crs_nameInput,weekday=self.weekday, \
                                                crs_list=self.crsList,std_info=self.crsStudent, \
                                                tch_cmt=self.eachStd)
            print('完成')
            return infos

        def read_scores(place_input, term, weekday):
            print('正在读取积分信息……', end='')
            wd = days_calculate.num_to_ch(str(weekday))
            xls_this = os.path.join(self.std_sig_dir, self.place_input,
                                    '学生信息表', term + '-学生信息表(周' + wd + ').xlsx')
            df_this_crs_score = WashData.std_score_this_crs(xls_this)

            place_dir = os.path.join(self.std_sig_dir, self.place_input)
            df_all_scores = WashData.std_all_scores(place_dir)

            print('完成')
            return {
                'this_score': df_this_crs_score,
                'all_scores': df_all_scores
            }

        def pic_xy(picWid, picHig, x0, y0):
            #白色矩形
            recX0 = x0
            recY0 = y0
            recX1 = x0 + picWid + 10
            recY1 = y0 + picHig + 10

            #照片
            picX0 = recX0 + 5
            picY0 = recY0 + 5
            picX1 = picX0 + picWid
            picY1 = picY0 + picHig

            return [[int(recX0),
                     int(recY0),
                     int(recX1),
                     int(recY1)],
                    [int(picX0),
                     int(picY0),
                     int(picX1),
                     int(picY1)]]

        def color_list(list_num='202002'):
            colors_202002 = {
                'title_bg': '#FF9E11',  #乐高机器人课
                'name': '#FFFFFF',  # 姓名 年龄
                'crs': '#00b578',  #课程
                'pics': '#f7f7f7',  #照片大框
                'pics_box': '#ffffff',  #照片相框
                'pic01': '#ffffff',
                'pic02': '#ffffff',
                'pic03': '#ffffff',
                'pic04': '#ffffff',
                'comments': '#00bde3',  #老师评语
                'logo': '#ffffff',  #logo
                't_title_ke1': '#ffffff',
                't_title_xue': '#ffffff',
                't_title_ji': '#ffffff',
                't_title_qi': '#ffffff',
                't_title_ren': '#ffffff',
                't_title_ke4': '#ffffff',
                'scores': '#f7f7f7',  #积分底色
                'score_left': '#ffffff',
                'score_right': '#ffffff',
                't_name': '#00b578',  #姓名
                't_kdgtn': '#00b578',  #幼儿园
                't_class': '#00b578',  #班级
                't_crs': '#FFE340',  #课程名称
                't_diff': '#ffffff',  #难度
                't_tool': '#ffffff',  #教具
                't_knlg': '#ffffff',  #知识点
                't_date': '#ffffff',  #日期
                't_scores_left': '#8b988e',  #积分文字
                't_scores_right': '#8b988e',  #积分文字
                't_scores_title': '#8b988e',  #积分标题
                't_tch_cmt_title': '#795022',  #老师评语标题
                't_tch_cmt': '#ffffff',  #老师评语
                't_tch_sig': '#ffffff',  #签名
                't_bottom': '#656564'  #二维码文字
            }
            colors_202101 = {
                'title_bg': '#f7f3c3',  #乐高机器人课
                'name': '#FFFFFF',  # 姓名 年龄
                'crs': '#f1f9ee',  #课程
                'pics': '#f7f7f7',  #照片大框
                'pics_box': '#ffffff',  #照片相框
                'pic01': '#ffffff',
                'pic02': '#ffffff',
                'pic03': '#ffffff',
                'pic04': '#ffffff',
                'scores': '#f7f7f7',  #积分底色
                'score_left': '#ffffff',
                'score_right': '#ffffff',
                'comments': '#f9f9f9',  #老师评语
                'logo': '#ffffff',  #logo
                't_title_ke1': '#009ce6',
                't_title_xue': '#33b171',
                't_title_ji': '#ef9c10',
                't_title_qi': '#8bbe19',
                't_title_ren': '#dc9ee7',
                't_title_ke4': '#b18046',
                't_name': '#99633f',  #姓名
                't_kdgtn': '#99633f',  #幼儿园
                't_class': '#99633f',  #班级
                't_crs': '#37a751',  #课程名称
                't_diff': '#8b988e',  #难度
                't_tool': '#8b988e',  #教具
                't_knlg': '#8b988e',  #知识点
                't_date': '#8b988e',  #日期
                't_scores_left': '#cc8e28',  #积分文字
                't_scores_right': '#c8bb9b',  #积分文字
                't_scores_title': '#b4b4b5',  #积分标题
                't_tch_cmt_title': '#b4b4b5',  #老师评语标题
                't_tch_cmt': '#795022',  #老师评语
                't_tch_sig': '#795022',  #签名
                't_bottom': '#656564'  #二维码文字
            }

            out = eval('colors_' + list_num)

            return out

        def basic_bg(num):
            color = color_list('202101')

            # y1:第一块左上角纵坐标,y1_2:第一块右下角纵坐标,以此类推
            # y及s后面的数字代表:
            # 1——标题
            # 2——姓名、机构
            # 3——课程、知识点
            # 4——照片(2张或4张)
            # 5——课堂情况(老师评论),可变,随评论多少而改变。
            # score——积分
            # 6——logo、二维码

            s1 = 100
            s2 = 140
            s3 = 450
            s4 = 700
            self.s4 = s4

            #评论的高度
            s5 = (self.comment_font_size +
                  self.comment_dis_line) * self.para_num + 160
            self.s5 = s5

            #积分的高度
            s_score = 380

            #logo的高度
            s6 = 200
            self.s6 = s6
            sprt = 10

            if num > 3:
                total_len = s1 + s2 + s3 + s4 + s_score + s5 + s6 + sprt * 6
            else:
                total_len = s1 + s2 + s3 + s4 + s_score + s5 + s6 + sprt * 6 - s4 // 2

            #标题坐标
            y1 = 0
            y1_2 = y1 + s1
            #姓名、机构坐标
            y2 = y1_2 + sprt
            y2_2 = y2 + s2
            #课程及知识点坐标
            y3 = y2_2 + sprt
            y3_2 = y3 + s3
            #照片坐标
            y4 = y3_2 + sprt
            if num > 3:
                y4_2 = y4 + s4
            else:
                y4_2 = y4 + s4 // 2
            self.y4 = y4
            self.y4_2 = y4_2
            #课堂情况(老师评论)坐标,变量
            y5 = y4_2 + sprt
            y5_2 = y5 + s5
            self.y5 = y5
            self.y5_2 = y5_2
            #积分坐标
            y_score = y5_2 + sprt
            y_score_2 = y_score + s_score
            self.y_score = y_score
            self.y_score_2 = y_score_2
            #logo、二维码坐标
            y6 = y_score_2 + sprt
            y6_2 = y6 + s6
            self.y6 = y6
            self.y6_2 = y6_2

            if num == 4:
                img = Image.new("RGB", (900, total_len), (255, 255, 255))
                draw = ImageDraw.Draw(img)
                draw.rectangle([(0, 0), (900, y1_2)],
                               fill=color['title_bg'])  #乐高机器人课
                draw.rectangle([(0, y2), (900, y2_2)],
                               fill=color['name'])  # 姓名 年龄
                draw.rectangle([(0, y3), (900, y3_2)], fill=color['crs'])  # 课程
                draw.rectangle([(0, y4), (900, y4_2)],
                               fill=color['pics'])  # 照片
                draw.rectangle([(0, y5), (300, y5 + 80)],
                               fill=color['comments'])  # 能力测评标题背景
                draw.rectangle([(0, y5 + 80), (900, y5_2)],
                               fill=color['comments'])  # 能力测评
                draw.rectangle([(0, y6), (900, y6_2)],
                               fill=color['logo'])  # logo

                draw.rectangle([(pic0[0][0], pic0[0][1]),
                                (pic0[0][2], pic0[0][3])],
                               fill=color['pics_box'])  #相框_课程
                draw.rectangle([(pic1[0][0], pic1[0][1]),
                                (pic1[0][2], pic1[0][3])],
                               fill=color['pic01'])  #相框_1
                draw.rectangle([(pic2[0][0], pic2[0][1]),
                                (pic2[0][2], pic2[0][3])],
                               fill=color['pic02'])  #相框_2
                draw.rectangle([(pic3[0][0], pic3[0][1]),
                                (pic3[0][2], pic3[0][3])],
                               fill=color['pic03'])  #相框_3
                draw.rectangle([(pic4[0][0], pic4[0][1]),
                                (pic4[0][2], pic4[0][3])],
                               fill=color['pic04'])  #相框_4

                draw.rectangle([(0, y_score), (300, y_score + 80)],
                               fill=color['scores'])  #积分标题背景
                draw.rectangle([(0, y_score + 80), (900, y_score_2)],
                               fill=color['scores'])  #积分
                draw.rectangle([(20, y_score + 80 + 20),
                                (440, y_score_2 - 20)],
                               fill=color['score_left'])  #积分左
                draw.rectangle([(460, y_score + 80 + 20),
                                (880, y_score_2 - 20)],
                               fill=color['score_right'])  #积分右
            elif num == 2:
                img = Image.new("RGB", (900, int(total_len)), (255, 255, 255))
                draw = ImageDraw.Draw(img)
                draw.rectangle([(0, 0), (900, y1_2)],
                               fill=color['title_bg'])  #乐高机器人课
                draw.rectangle([(0, y2), (900, y2_2)],
                               fill=color['name'])  # 姓名 年龄
                draw.rectangle([(0, y3), (900, y3_2)], fill=color['crs'])  # 课程
                draw.rectangle([(0, y4), (900, y4_2)],
                               fill=color['pics'])  # 照片
                draw.rectangle([(0, y5), (300, y5 + 80)],
                               fill=color['comments'])  # 能力测评标题背景
                draw.rectangle([(0, y5 + 80), (900, y5_2)],
                               fill=color['comments'])  # 能力测评
                draw.rectangle([(0, y6), (900, y6_2)],
                               fill=color['logo'])  # logo

                draw.rectangle([(pic0[0][0], pic0[0][1]),
                                (pic0[0][2], pic0[0][3])],
                               fill=color['pics_box'])  #相框_课程
                draw.rectangle([(pic1[0][0], pic1[0][1]),
                                (pic1[0][2], pic1[0][3])],
                               fill=color['pic01'])  #相框_1
                draw.rectangle([(pic2[0][0], pic2[0][1]),
                                (pic2[0][2], pic2[0][3])],
                               fill=color['pic02'])  #相框_2
                # draw.rectangle([(pic3[0][0],pic3[0][1]),(pic3[0][2],pic3[0][3])],fill=color['pic03']) #相框_3
                # draw.rectangle([(pic4[0][0],pic4[0][1]),(pic4[0][2],pic4[0][3])],fill=color['pic04']) #相框_4
                draw.rectangle([(0, y_score), (300, y_score + 80)],
                               fill=color['scores'])  #积分标题背景
                draw.rectangle([(0, y_score + 80), (900, y_score_2)],
                               fill=color['scores'])  #积分
                draw.rectangle([(20, y_score + 80 + 20),
                                (440, y_score_2 - 20)],
                               fill=color['score_left'])  #积分左
                draw.rectangle([(460, y_score + 80 + 20),
                                (880, y_score_2 - 20)],
                               fill=color['score_right'])  #积分右

            return img

        def pick_pics(stdName):
            # print('stdname:',stdName)
            pic_title_addr = os.path.join(self.ConsDir, crs_nameInput,
                                          crs_name + '.jpg')  #课程的标题图

            ptn = '-.*-'
            pics_for_crs = []

            for root, dirs, files in os.walk(
                    os.path.join(self.picStdDir, stdName)):  #学员的照片
                for file in files:
                    try:
                        if re.findall(ptn, file)[0][1:-1] == crs_nameInput:
                            PicTags = readConfig.code_to_str(
                                iptcinfo3.IPTCInfo(
                                    os.path.join(self.picStdDir, stdName,
                                                 file)))
                            # print('tags:',PicTags)
                            if '每周课程4+' in PicTags:
                                pics_for_crs.append(
                                    os.path.join(self.picStdDir, stdName,
                                                 file))
                    except:
                        pass
            # print(pics_for_crs)
            # pics=pick_pics(stdName)
            if len(pics_for_crs) > 3:
                num = 4
            else:
                num = 2

            # print('number:',num)
            # print(pics_for_crs)
            pics_stds_addrs = random.sample(pics_for_crs, num)

            # print(pics_stds_addrs)
            sorted_pics_stds_addrs = sortPics(pics_stds_addrs)
            pics = [pic_title_addr]
            pics.extend(sorted_pics_stds_addrs)
            return pics

        def putImg(img, stdName):
            print('    正在置入图片……', end='')
            pics = pick_pics(stdName)

            if self.bg_img_num > 3:
                f_crs, f_01, f_02, f_03, f_04 = pics

                pic_crs = self.pic_resize(Image.open(f_crs), picWid)
                pic_01 = self.pic_resize(Image.open(f_01), picWid)
                pic_02 = self.pic_resize(Image.open(f_02), picWid)
                pic_03 = self.pic_resize(Image.open(f_03), picWid)
                pic_04 = self.pic_resize(Image.open(f_04), picWid)
                _pic_logo = Image.open(
                    'I:\\大智小超\\公共素材\\图片类\\大智小超新logo.png').convert('RGBA')
                pic_logo = _pic_logo.resize((350, int(350 / 2.76)))
                r, g, b, a = pic_logo.split()

                _pic_qrcode = Image.open(
                    'I:\\大智小超\\公共素材\\图片类\\大智小超视频号二维码2.png')
                pic_qrcode = _pic_qrcode.resize((130, 130))

                _pic_award = Image.open('I:\\大智小超\\公共素材\\图片类\\奖状.png')
                pic_award = _pic_award.resize((420, 420 * 261 // 419))
                r_ad, g_ad, b_ad, a_ad = pic_award.split()

                logging.info('照片尺寸:' + ','.join(self.sstr(pic_crs.size)))
                img.paste(pic_crs, (pic0[1][0], pic0[1][1]))
                img.paste(pic_01, (pic1[1][0], pic1[1][1]))
                img.paste(pic_02, (pic2[1][0], pic2[1][1]))
                img.paste(pic_03, (pic3[1][0], pic3[1][1]))
                img.paste(pic_04, (pic4[1][0], pic4[1][1]))
                img.paste(pic_logo,
                          (50, int(self.y6 + self.s6 / 2 - 350 / 2.76 / 2)),
                          mask=a)
                img.paste(pic_qrcode,
                          (700, int(self.y6 + self.s6 / 2 - 130 / 2)))
                img.paste(pic_award, (20, self.y_score + 100), mask=a_ad)
            else:
                f_crs, f_01, f_02 = pics

                pic_crs = self.pic_resize(Image.open(f_crs), picWid)
                pic_01 = self.pic_resize(Image.open(f_01), picWid)
                pic_02 = self.pic_resize(Image.open(f_02), picWid)

                _pic_logo = Image.open(
                    'I:\\大智小超\\公共素材\\图片类\\大智小超新logo.png').convert('RGBA')
                pic_logo = _pic_logo.resize((350, int(350 / 2.76)))
                r, g, b, a = pic_logo.split()

                _pic_qrcode = Image.open(
                    'I:\\大智小超\\公共素材\\图片类\\大智小超视频号二维码2.png')
                pic_qrcode = _pic_qrcode.resize((130, 130))

                _pic_award = Image.open('I:\\大智小超\\公共素材\\图片类\\奖状.png')
                pic_award = _pic_award.resize((420, 420 * 261 // 419))
                r_ad, g_ad, b_ad, a_ad = pic_award.split()

                logging.info('照片尺寸:' + ','.join(self.sstr(pic_crs.size)))
                img.paste(pic_crs, (pic0[1][0], pic0[1][1]))
                img.paste(pic_01, (pic1[1][0], pic1[1][1]))
                img.paste(pic_02, (pic2[1][0], pic2[1][1]))

                img.paste(pic_logo,
                          (50, int(self.y6 + self.s6 / 2 - 350 / 2.76 / 2)),
                          mask=a)
                img.paste(pic_qrcode,
                          (700, int(self.y6 + self.s6 / 2 - 130 / 2)))
                img.paste(pic_award, (20, self.y_score + 100), mask=a_ad)

            print('完成')

        def expScript(name_input):
            stdname = name_input
            nickname = teacherCmt[teacherCmt['学生姓名'] ==
                                  stdname]['昵称'].values.tolist()[0]
            teacherCmtTxt = teacherCmt[teacherCmt['学生姓名'] == stdname][
                str(dateInput) + '-' + crs_nameInput].values.tolist()[0]

            # if teacherCmtTxt=='-':
            #     teacherCmtTxt=teacherCmt[teacherCmt['学生姓名']=='通用评论'][str(dateInput)+'-'+crs_nameInput].values.tolist()[0]
            prsTxt = random.choice(self.PraiseTxt)
            if teacherCmtTxt != '-':
                script = stdname + '同学在“' + crs_info[0] + '”这节课中,' + crs_info[
                    2] + '\n' + teacherCmtTxt
            else:
                # script=stdname+'同学在“'+crs_info[0]+'”这节课中,'+crs_info[2]+'\n'+prsTxt
                #如果该学生评论为空,则读取通用评论。
                script = stdname + '同学在“' + crs_info[0] + '”这节课中,' + crs_info[
                    2] + '\n' + teacherCmt[teacherCmt['学生姓名'] == '通用评论'][str(
                        dateInput) + '-' + crs_nameInput].values.tolist()[0]

            if '#' in script:
                script = script.replace('#', stdname)
            if '$' in script:
                if nickname == '-':
                    nickname = stdname
                script = script.replace('$', nickname)

            return script

        def get_std_scores(date_input, crs_name, std_name, df_this_crs_score):
            this_score = df_this_crs_score['this_score']
            std_this_score = this_score[this_score['学生姓名'] == std_name][
                str(date_input) + '-' + crs_name].tolist()[0]

            all_scores = df_this_crs_score['all_scores']
            df_std_all_scores = all_scores[all_scores['学生姓名'] == std_name]
            crs_sc = df_std_all_scores['课堂总积分'].tolist()[0]
            vrfy_sc = df_std_all_scores['核销积分'].tolist()[0]
            remain_sc = df_std_all_scores['剩余积分'].tolist()[0]
            std_all_scores = {
                'crs_sc': crs_sc,
                'vrfy_sc': vrfy_sc,
                'remain_sc': remain_sc
            }

            return {
                'std_this_score': std_this_score,
                'std_all_scores': std_all_scores
            }

        def putTxt(img, stdName, stdAge, KdgtName, ClassName):
            print('    正在置入文本……', end='')
            color = color_list('202101')
            draw = ImageDraw.Draw(img)

            draw.text((170, 5),
                      '科',
                      fill=color['t_title_ke1'],
                      font=self.fonts('汉仪超级战甲', 75))  #大题目
            draw.text((270, 5),
                      '学',
                      fill=color['t_title_xue'],
                      font=self.fonts('汉仪超级战甲', 75))  #大题目
            draw.text((370, 5),
                      '机',
                      fill=color['t_title_ji'],
                      font=self.fonts('汉仪超级战甲', 75))  #大题目
            draw.text((470, 5),
                      '器',
                      fill=color['t_title_qi'],
                      font=self.fonts('汉仪超级战甲', 75))  #大题目
            draw.text((570, 5),
                      '人',
                      fill=color['t_title_ren'],
                      font=self.fonts('汉仪超级战甲', 75))  #大题目
            draw.text((670, 5),
                      '课',
                      fill=color['t_title_ke4'],
                      font=self.fonts('汉仪超级战甲', 75))  #大题目
            draw.text((350, 120),
                      stdName,
                      fill=color['t_name'],
                      font=self.fonts('汉仪心海行楷w', 60))  #姓名
            # draw.text((530,160), str(stdAge)+'岁', fill = '#6AB34A',font=self.fonts('微软雅黑',60))  #年龄
            draw.text((280, 200),
                      KdgtName,
                      fill=color['t_kdgtn'],
                      font=self.fonts('杨任东竹石体', 33))  #幼儿园
            draw.text((460, 200),
                      ClassName,
                      fill=color['t_class'],
                      font=self.fonts('杨任东竹石体', 33))  #班级

            draw.text((50, 290),
                      '• ' + crs_info[0] + ' •',
                      fill=color['t_crs'],
                      font=self.fonts('华康海报体W12(p)', 40))  #课程名称
            draw.text((50, 360),
                      '难度:' + crs_info[3],
                      fill=color['t_diff'],
                      font=self.fonts('汉仪锐智w', 25))  #难度
            draw.text((530, 630),
                      '使用教具:' + crs_info[4],
                      fill=color['t_tool'],
                      font=self.fonts('微软雅黑', 22))  #教具

            self.put_txt_img(img,
                             crs_info[1],
                             450, [25, 420],
                             25,
                             fill=color['t_knlg'],
                             font_name='汉仪锐智w',
                             font_size=28)  #知识点

            date_txt = '-'.join(
                [str(dateInput)[0:4],
                 str(dateInput)[4:6],
                 str(dateInput)[6:]])
            draw.text((100, 630),
                      date_txt,
                      fill=color['t_date'],
                      font=self.fonts('汉仪心海行楷w', 35))  #日期

            #评语&积分
            script = expScript(stdName)
            self.put_txt_img(img,
                             script,
                             780, [60, self.y5 + 115],
                             20,
                             fill=color['t_tch_cmt'],
                             font_name='汉仪字酷堂经解楷体w',
                             font_size=36,
                             addSPC='add_2spaces')  #老师评语
            draw.text((650, int(self.y5_2 - 80)),
                      TeacherSig,
                      fill=color['t_tch_sig'],
                      font=self.fonts('汉仪字酷堂经解楷体w', 45))  #签名
            draw.text((500, int(self.y6 + self.s6 / 2 - 35)),
                      '长按二维码 → \n关注视频号 →',
                      fill=color['t_bottom'],
                      font=self.fonts('微软雅黑', 30))
            draw.text((20, self.y5 + 5),
                      '我的课堂情况',
                      fill=color['t_tch_cmt_title'],
                      font=self.fonts('汉仪糯米团', 45))  #我的课堂情况
            draw.text((60, self.y_score + 5),
                      '我的积分',
                      fill=color['t_scores_title'],
                      font=self.fonts('汉仪糯米团', 45))  #我的积分
            draw.text((120, self.y_score + 120),
                      '本节课积分',
                      fill=color['t_scores_left'],
                      font=self.fonts('汉仪糯米团', 45))  #本节课积分

            std_scores = get_std_scores(date_input=dateInput,
                                        crs_name=crs_nameInput,
                                        std_name=stdName,
                                        df_this_crs_score=df_std_scores)
            std_this_score = std_scores['std_this_score']
            crs_total_sc = std_scores['std_all_scores']['crs_sc']
            remain_sc = std_scores['std_all_scores']['remain_sc']
            vrfy_sc = std_scores['std_all_scores']['vrfy_sc']

            draw.text((210, self.y_score + 200),
                      str(std_this_score) + '分',
                      fill=color['t_scores_left'],
                      font=self.fonts('汉仪糯米团', 75))  #本节课积分
            draw.text((490, self.y_score + 160),
                      '可兑换积分:' + str(int(remain_sc)) + ' 分',
                      fill=color['t_scores_right'],
                      font=self.fonts('优设标题', 35))  #可兑换积分
            draw.text((490, self.y_score + 210),
                      '累计积分:' + str(int(crs_total_sc)) + ' 分',
                      fill=color['t_scores_right'],
                      font=self.fonts('优设标题', 35))  #累计总积分
            draw.text((490, self.y_score + 260),
                      '已兑换积分:' + str(int(vrfy_sc)) + ' 分',
                      fill=color['t_scores_right'],
                      font=self.fonts('优设标题', 35))  #消耗积分

            print('完成')

        para = basic_para()

        picWid,picX1,picX2,picX3,picX4,picY1,picY2,picY3,picY4,pic0,pic1,pic2,pic3,pic4= \
        para[0],para[1],para[2],para[3],para[4],para[5],para[6],para[7],para[8],para[9],para[10],para[11],para[12],para[13]

        INFO = read_excel()
        df_std_scores = read_scores(place_input=self.place_input,
                                    term=self.term,
                                    weekday=self.weekday)
        std_list, crs_info, teacherCmt = INFO['std_list'], INFO[
            'crs_info'], INFO['tch_cmt']

        for std in std_list:
            print('正在处理 {} 的图片:'.format(std[3]))
            # img=basic_bg()
            KdgtName, ClassName, stdPY, stdName, stdAge = std[0], std[1], std[
                2], std[3], '-'
            totalTxt = expScript(stdName)
            self.allTxt, self.para_num = composing.split_txt_Chn_eng(
                wid=780,
                font_size=self.comment_font_size,
                txt_input=totalTxt,
                Indent='yes')

            self.bg_img_num = len(pick_pics(std[2] + std[3]))
            if self.bg_img_num > 3:
                img = basic_bg(4)
            else:
                img = basic_bg(2)

            putImg(img, stdPY + stdName)
            putTxt(img, stdName, stdAge, KdgtName, ClassName)

            print('正在保存 {} 的图片……'.format(std[3]), end='')
            if not os.path.exists(
                    os.path.join(self.bg,
                                 str(dateInput)[0:4],
                                 str(dateInput) + '-' + crs_nameInput)):
                os.mkdir(
                    os.path.join(self.bg,
                                 str(dateInput)[0:4],
                                 str(dateInput) + '-' + crs_nameInput))

            img.save(
                os.path.join(
                    self.bg,
                    str(dateInput)[0:4],
                    str(dateInput) + '-' + crs_nameInput, std[2] + stdName +
                    '-' + str(dateInput) + '-' + crs_nameInput + '.jpg'))
            print('完成')
            # img.show()

        print('\n全部完成,保存文件夹:{} 下面的学生文件名'.format(self.bg))
Esempio n. 6
0
    def exp_poster(self,std_name='韦宇浠',start_date='20200930',end_date='20210121',cmt_date='20210407', \
                    tb_list=[['2020秋','w2'],['2021春','w4']],tch_name='阿晓老师',mode='all',k=1):
        print('正在处理……')
        info = self.get_std_term_crs(std_name=std_name,
                                     tb_list=tb_list,
                                     start_date=start_date,
                                     end_date=end_date)
        total_crs = info['total_crs']
        total_crs.dropna(inplace=True)
        std_crs = info['std_crs']
        std_crs.dropna(inplace=True)
        std_info = info['std_info']

        #学期课程总数
        total_crs_num = total_crs.shape[0]
        #格子的行数
        if total_crs_num / 4 == total_crs_num // 4:
            crs_lines = total_crs_num // 4
        else:
            crs_lines = total_crs_num // 4 + 1

        #所有课程格子的总高度
        ht_crs = int((170 * k + 14 * k) * crs_lines)

        #学生基本信息
        std_school = std_info['机构'].values[0]
        std_class = std_info['班级'].values[0]

        #学生学期末评语
        term, weekday = tb_list[-1][0], tb_list[-1][1][1]
        wd = days_calculate.num_to_ch(weekday)
        xls = os.path.join(self.feedback_dir,
                           term + '-学生课堂学习情况反馈表(周' + wd + ').xlsx')
        comments = WashData.std_feedback(std_name=std_name,
                                         xls=xls)['df_term_comment']
        comments_for_std = comments[comments['学生姓名'] == std_name][
            term + '学期总结-' + str(cmt_date)].values.tolist()[0].replace(
                '#', std_name)
        std_crs_num = std_crs.shape[0]
        if mode == 'part':
            if total_crs_num == std_crs_num:
                std_crs_num_txt = '{0}同学在上一阶段的{1} 节科学机器人课中,完成了全部课程的学习!'.format(
                    std_name, total_crs_num)
            else:
                std_crs_num_txt = '{0}同学在上一阶段的{1} 节科学机器人课中,完成了{2} 节课的学习,请假{3} 节。'.format(
                    std_name, total_crs_num, std_crs_num,
                    total_crs_num - std_crs_num)
        elif mode == 'all':
            # if  total_crs_num==std_crs_num:
            std_crs_num_txt = '{0}已经完成了{1} 节科学机器人课程的学习!'.format(
                std_name, total_crs_num)
            # else:
            # std_crs_num_txt='{0}同学在上一阶段的{1} 节科学机器人课中,完成了{2} 节课的学习,请假{3} 节。'.format(std_name,total_crs_num,std_crs_num,total_crs_num-std_crs_num)

        comments_for_std = std_crs_num_txt + '\n' + comments_for_std
        font_size_cmt = int(30 * k)
        prgh_nums = composing.split_txt_Chn_eng(wid=int(636 * k),
                                                font_size=font_size_cmt,
                                                txt_input=comments_for_std)[1]
        #评语标题高度
        ht_cmt_title = int(60 * k)
        #评语高度
        ht_prgh = int(font_size_cmt * 1.5 * (prgh_nums + 4))

        ht_title = int(110 * k)
        ht_std = int(100 * k)
        ht_bottom = int(210)
        gap_0 = int(12 * k)
        gap_1 = int(13 * k)

        y_std_1 = int(120 * k)
        y_std_2 = int((y_std_1 + 100))

        blocks = [ht_title, ht_std, ht_crs, ht_cmt_title, ht_prgh, ht_bottom]

        #计算总的高度
        ht_total_bg = int((sum(blocks) + gap_0 * 4 + gap_1 * (prgh_nums - 1)))

        #课程标题坐标
        y_crs_title = int((y_std_2 + gap_0 + 80))

        #课程格最左上角坐标
        y_left_up = int((y_crs_title + gap_0))

        #评语绿底右下坐标
        y_cmt_bg = y_left_up + ht_crs + gap_0 + ht_cmt_title + ht_prgh + 30

        # draw.rectangle([(int(36*k),y_left_up+gap_0+ht_cmt_title+10),(int(684*k),y_cmt_bg)],fill='#F3F3E4')

        def draw_bg():
            bg = Image.new('RGBA', (int(720 * k), ht_total_bg), '#F3F9E4')
            draw = ImageDraw.Draw(bg)
            #白底
            draw.rectangle([(int(13 * k), int(110 * k)),
                            (int(707 * k), ht_total_bg - 25)],
                           fill='#FFFFFF')
            #名字绿底
            draw.rectangle([(int(36), y_std_1), (int(250 * k), y_std_2)],
                           fill='#F3F9E4')
            draw.rectangle([(int(36), y_std_2), (int(684 * k), y_std_2 + 2)],
                           fill='#F3F9E4')

            return bg

        def crs_pic(total_crs=total_crs, std_crs=std_crs, odr=0):
            wid_crs, ht_crs = int(150 * k), int(170 * k)

            #学生上过的课程和总课程的差集
            sub_set = total_crs.copy()
            sub_set = sub_set.append(std_crs)
            sub_set = sub_set.append(std_crs)
            sub_set.drop_duplicates(subset=['课程名称'], keep=False, inplace=True)

            crs_bg = Image.new('RGB', (wid_crs, ht_crs), '#F3F3E4')
            crs_name = total_crs.iloc[odr, :]['课程名称']
            crs_date = total_crs.iloc[odr, :]['上课日期']
            crs_pic = Image.open(
                os.path.join(self.design_dir, crs_name, crs_name[4:] + '.jpg'))
            crs_pic = crs_pic.crop((560, 0, 1280, 720)).resize(
                (int(110 * k), int(110 * k)))
            crs_bg.paste(crs_pic, (int(20 * k), int(6 * k)))
            draw = ImageDraw.Draw(crs_bg)
            ft_size = int(19 * k)
            x_txt = int(((150 * k - len(crs_name[4:]) * ft_size) / 2 + 3))

            draw.text((x_txt, int(122 * k)),
                      crs_name[4:],
                      fill='#8fc31f',
                      font=self.font('方正韵动粗黑简', ft_size))  #课程名称

            #判断是否有不上的课,如有,变灰
            if crs_name not in sub_set['课程名称'].values:
                draw.text((int(35 * k), int(148 * k)),
                          str(crs_date)[:11],
                          fill='#8fc31f',
                          font=self.font('方正韵动粗黑简', int(12 * k)))  #课程日期
            else:
                draw.text((int(35 * k), int(148 * k)),
                          '---------',
                          fill='#8fc31f',
                          font=self.font('方正韵动粗黑简', int(12 * k)))  #课程日期

                crs_bg = ImageEnhance.Brightness(crs_bg).enhance(1.4)
                crs_bg = crs_bg.convert('L')

            # crs_bg.show()
            return crs_bg

        def draw_crs():
            print('正在生成图片……', end='')

            #使用并改变母函数的变量
            nonlocal y_left_up
            bg = draw_bg()
            wid_crs, ht_crs = int(150 * k), int(170 * k)

            draw = ImageDraw.Draw(bg)
            #分隔线
            draw.rectangle([(int(36 * k), y_crs_title),
                            (int(684 * k), y_crs_title + 2 * k)],
                           fill='#F3F3E4')

            cnt = 0
            for i in range(crs_lines):
                x_begin = int(40 * k)
                for j in range(4):
                    if cnt < total_crs_num:
                        crs_block = crs_pic(total_crs=total_crs,
                                            std_crs=std_crs,
                                            odr=cnt)
                        bg.paste(crs_block, (x_begin, y_left_up))
                        x_begin = x_begin + wid_crs + int(13 * k)
                        cnt += 1
                y_left_up = y_left_up + ht_crs + gap_1

            #分隔线
            draw.rectangle([(int(36 * k), y_left_up + gap_0),
                            (int(684 * k), y_left_up + gap_0 + 2)],
                           fill='#F3F3E4')
            #评语绿底
            # y_cmt_bg=y_left_up+gap_0+ht_cmt_title+ht_prgh
            draw.rectangle(
                [(int(36 * k), y_left_up + gap_0 + ht_cmt_title + 10),
                 (int(684 * k), y_cmt_bg)],
                fill='#F3F3E4')

            #二维码,logo
            _pic_logo = Image.open(
                'I:\\大智小超\\公共素材\\图片类\\大智小超新logo.png').convert('RGBA')
            pic_logo = _pic_logo.resize((int(210 * k), int(210 * k / 2.76)))
            r, g, b, a = pic_logo.split()

            y_logo = int((ht_total_bg - 140))

            _pic_qrcode = Image.open('I:\\大智小超\\公共素材\\图片类\\大智小超视频号二维码2.png')
            pic_qrcode = _pic_qrcode.resize((int(100 * k), int(100 * k)))

            bg.paste(pic_logo, (int(40 * k), int(y_logo + 10)), mask=a)
            bg.paste(pic_qrcode, (int(580 * k), int(y_logo - 10)))

            #文字部分
            #标题
            draw.text((int(130 * k), int(5 * k)),
                      '科学机器人课',
                      fill='#8fc31f',
                      font=self.font('汉仪超级战甲', int(78 * k)))
            #姓名班级
            draw.text((int(60 * k * 0.9), int(142 * k * 0.9)),
                      std_name,
                      fill='#F8B62D',
                      font=self.font('汉仪字酷堂义山楷w', int(60 * k)))
            draw.text((int(400 * k * 0.9), int(182 * k * 0.9)),
                      std_school + ' ' + std_class,
                      fill='#6C8466',
                      font=self.font('汉仪字酷堂义山楷w', int(30 * k)))
            draw.text((int(45), int((y_crs_title - 52))),
                      '点亮的课程',
                      fill='#8fc31f',
                      font=self.font('鸿蒙印品', int(35 * k)))
            draw.text((int(45), int((y_left_up + gap_0 + 20))),
                      '学期评语',
                      fill='#8fc31f',
                      font=self.font('鸿蒙印品', int(35 * k)))

            #评语
            composing.put_txt_img(draw=draw,tt=comments_for_std,total_dis=int(628*k*0.95), \
                                  xy=[int(58),int((y_left_up+gap_0+110))],dis_line=int(20*k),fill='#595757', \
                                  font_name='丁永康硬笔楷书',font_size=font_size_cmt,addSPC="add_2spaces")

            draw.text((int(520 * k), int((y_cmt_bg - 46))),
                      tch_name,
                      fill='#595757',
                      font=self.font('丁永康硬笔楷书', 35))

            draw.text((int(380 * k), int((y_logo + 10))),
                      '长按二维码 → \n关注视频号 →',
                      fill='#8E9184',
                      font=self.font('微软雅黑', 25))

            bg = bg.convert('RGB')
            savename = os.path.join(
                self.term_pic_dir,
                std_name + '-' + cmt_date + '-' + term + '阶段小结.jpg')
            bg.save(savename, quality=90, subsampling=0)
            # bg.show()
            print('图片保存完成,保存路径:{}'.format(savename))

        draw_crs()
Esempio n. 7
0
    def exp_a4_16(self,std_name='韦宇浠',start_date='20200930',end_date='20210121',cmt_date='20210407', \
                        tb_list=[['2020秋','w2'],['2021春','w4']],tch_name='阿晓老师',mode='only16',k=1):
        print('正在处理……')
        info = self.get_std_term_crs(std_name=std_name,
                                     tb_list=tb_list,
                                     start_date=start_date,
                                     end_date=end_date)
        total_crs = info['total_crs']
        total_crs.dropna(inplace=True)
        std_crs = info['std_crs']
        std_crs.dropna(inplace=True)
        std_info = info['std_info']

        if mode == 'only16':
            # if len(std_crs)<16:
            #     print('{} 在{} - {} 期间总共上了{}节课,未上满16节。未生成报告。'.format(std_name,start_date,end_date,len(std_crs)))
            #     exit(0)
            total_crs = std_crs
            #学期课程总数
            total_crs_num = 16
            crs_lines = 2
        else:
            #学期课程总数
            total_crs_num = total_crs.shape[0]
            # 格子的行数
            if total_crs_num / 8 == total_crs_num // 8:
                crs_lines = total_crs_num // 8
            else:
                crs_lines = total_crs_num // 8 + 1

        #所有课程格子的总高度
        ht_crs = int((316 + 30) * crs_lines)

        #学生基本信息
        std_school = std_info['机构'].values[0]
        std_class = std_info['班级'].values[0]

        #学生学期末评语
        term, weekday = tb_list[-1][0], tb_list[-1][1][1]
        wd = days_calculate.num_to_ch(weekday)
        xls = os.path.join(self.feedback_dir,
                           term + '-学生课堂学习情况反馈表(周' + wd + ').xlsx')
        comments = WashData.std_feedback(std_name=std_name,
                                         xls=xls)['df_term_comment']
        comments_for_std = comments[comments['学生姓名'] == std_name][
            term + '学期总结-能力-' + str(cmt_date)].values.tolist()[0].replace(
                '#', std_name)
        comments_for_std_psycho = comments[comments['学生姓名'] == std_name][
            term + '学期总结-心理-' + str(cmt_date)].values.tolist()[0].replace(
                '#', std_name)
        # print(std_crs)
        std_crs_num = std_crs.shape[0]
        # if  mode=='only16':
        #     if  total_crs_num==std_crs_num:
        #         std_crs_num_txt='{0}同学在上一阶段的{1} 节科学机器人课中,完成了全部课程的学习!'.format(std_name,total_crs_num)
        #     else:
        #         std_crs_num_txt='{0}同学在上一阶段的{1} 节科学机器人课中,完成了{2} 节课的学习,请假{3} 节。'.format(std_name,total_crs_num,std_crs_num,total_crs_num-std_crs_num)
        # elif mode=='all':
        #     # if  total_crs_num==std_crs_num:
        #     std_crs_num_txt='{0}已经完成了{1} 节科学机器人课程的学习!'.format(std_name,total_crs_num)
        # else:
        # std_crs_num_txt='{0}同学在上一阶段的{1} 节科学机器人课中,完成了{2} 节课的学习,请假{3} 节。'.format(std_name,total_crs_num,std_crs_num,total_crs_num-std_crs_num)

        # comments_for_std=std_crs_num_txt+'\n'+comments_for_std
        font_size_cmt = int(50 * k)
        prgh_nums = composing.split_txt_Chn_eng(wid=int(636 * k),
                                                font_size=font_size_cmt,
                                                txt_input=comments_for_std)[1]
        #评语标题高度
        ht_cmt_title = int(60 * k)
        #评语高度
        ht_prgh = int(font_size_cmt * 1.5 * (prgh_nums + 4))

        ht_title = int(110 * k)
        ht_std = int(100 * k)
        ht_bottom = int(210)
        gap_0 = int(12 * k)
        gap_1 = int(13 * k)

        y_std_1 = int(120 * k)
        y_std_2 = int((y_std_1 + 100))

        blocks = [ht_title, ht_std, ht_crs, ht_cmt_title, ht_prgh, ht_bottom]

        #计算总的高度
        # ht_total_bg=int((sum(blocks)+gap_0*4+gap_1*(prgh_nums-1)))
        ht_total_bg = 3508

        #课程标题坐标
        y_crs_title = int((y_std_2 + gap_0 + 80))
        # y_crs_title=

        #课程格最左上角坐标
        y_left_up = 800

        #评语绿底右下坐标
        y_cmt_bg = y_left_up + ht_crs + gap_0 + ht_cmt_title + ht_prgh + 30

        # draw.rectangle([(int(36*k),y_left_up+gap_0+ht_cmt_title+10),(int(684*k),y_cmt_bg)],fill='#F3F3E4')

        def draw_bg():
            bg = Image.new('RGBA', (2481, 3508), '#7197b4')
            draw = ImageDraw.Draw(bg)
            #白底
            draw.rectangle([(50, 54), (2431, 3454)], fill='#FFFFFF')
            #评论大框
            draw.rectangle([(166, 1720), (2315, 3202)],
                           fill='#FFFFFF',
                           outline='#7197b4',
                           width=2)
            #玫瑰图底色
            # draw.rectangle([(1595,1936),(2295,3155)],fill='#f0f8fb')
            # draw.rectangle([(1635,2695),(2255,2855)],fill='#ffffff')
            # draw.rectangle([(1635,2975),(2255,3125)],fill='#ffffff')

            #左边能力底色
            draw.rectangle([(206, 1740), (1246, 3182)], fill='#f0f8fb')
            draw.rectangle([(226, 2537), (1226, 3162)], fill='#ffffff')

            #右边心理底色
            draw.rectangle([(1275, 1740), (2295, 3182)], fill='#f0f8fb')
            draw.rectangle([(1295, 2537), (2275, 3162)], fill='#ffffff')

            return bg

        def crs_pic(total_crs=total_crs, std_crs=std_crs, odr=0):
            wid_crs, ht_crs = int(270 * k), int(351 * k)

            #学生上过的课程和总课程的差集
            sub_set = total_crs.copy()
            sub_set = sub_set.append(std_crs)
            sub_set = sub_set.append(std_crs)
            sub_set.drop_duplicates(subset=['课程名称'], keep=False, inplace=True)

            crs_bg = Image.new('RGB', (wid_crs, ht_crs), '#7197b4')
            crs_name = total_crs.iloc[odr, :]['课程名称']
            crs_date = total_crs.iloc[odr, :]['上课日期']
            crs_pic = Image.open(
                os.path.join(self.design_dir, crs_name, crs_name[4:] + '.jpg'))
            crs_pic = crs_pic.crop((560, 0, 1280, 720)).resize(
                (int(230 * k), int(230 * k)))
            crs_bg.paste(crs_pic, (int(20 * k), int(20 * k)))
            draw = ImageDraw.Draw(crs_bg)
            ft_size = int(30 * k)
            x_txt = int(((270 * k - len(crs_name[4:]) * ft_size) / 2 + 3))

            draw.text((x_txt, int(270 * k)),
                      crs_name[4:],
                      fill='#ffffff',
                      font=self.font('方正韵动粗黑简', ft_size))  #课程名称
            # draw.text((int(55*k),int(310*k)),str(crs_date)[:11],fill='#ffffff',font=self.font('方正韵动粗黑简',int(24*k))) #课程日期

            #判断是否有不上的课,如有,变灰
            if crs_name not in sub_set['课程名称'].values:
                draw.text((int(55 * k), int(310 * k)),
                          str(crs_date)[:11],
                          fill='#ffffff',
                          font=self.font('方正韵动粗黑简', int(24 * k)))  #课程日期
            else:
                draw.text((int(55 * k), int(310 * k)),
                          '---------',
                          fill='#ffffff',
                          font=self.font('方正韵动粗黑简', int(24 * k)))  #课程日期

                crs_bg = ImageEnhance.Brightness(crs_bg).enhance(1.4)
                crs_bg = crs_bg.convert('L')

        # crs_bg.show()
            return crs_bg

        def draw_crs():
            print('正在生成图片……', end='')

            #使用并改变母函数的变量
            nonlocal y_left_up
            bg = draw_bg()
            wid_crs, ht_crs = int(270 * k), int(351 * k)

            draw = ImageDraw.Draw(bg)
            #分隔线
            # draw.rectangle([(int(36*k),y_crs_title),(int(684*k),y_crs_title+2*k)],fill='#F3F3E4')

            cnt = 0
            for i in range(crs_lines):
                x_begin = int(80 * k)
                for j in range(8):
                    if cnt < total_crs_num:
                        try:
                            crs_block = crs_pic(total_crs=total_crs,
                                                std_crs=std_crs,
                                                odr=cnt)
                            bg.paste(crs_block, (x_begin, y_left_up))
                            x_begin = x_begin + wid_crs + int(23 * k)
                            cnt += 1
                        except Exception as e:
                            pass
                        continue
                y_left_up = y_left_up + ht_crs + gap_1

            #分隔线
            # draw.rectangle([(int(36*k),y_left_up+gap_0),(int(684*k),y_left_up+gap_0+2)],fill='#F3F3E4')
            #评语绿底
            # y_cmt_bg=y_left_up+gap_0+ht_cmt_title+ht_prgh
            # draw.rectangle([(int(36*k),y_left_up+gap_0+ht_cmt_title+10),(int(684*k),y_cmt_bg)],fill='#F3F3E4')

            #二维码,logo
            _pic_logo = Image.open(
                os.path.join(self.public_dir, '图片类',
                             '大智小超新logo.png')).convert('RGBA')
            pic_logo = _pic_logo.resize((int(330 * k), int(330 * k / 2.76)))
            r, g, b, a = pic_logo.split()

            y_logo = int((ht_total_bg - 240))

            _pic_qrcode = Image.open(
                os.path.join(self.public_dir, '图片类', '大智小超视频号二维码2.png'))
            pic_qrcode = _pic_qrcode.resize((int(210 * k), int(210 * k)))

            bg.paste(pic_logo, (int(130 * k), int(y_logo + 10)), mask=a)
            bg.paste(pic_qrcode, (int(2190 * k), int(y_logo - 40)))

            #玫瑰图
            rose_and_bar = self.rose_and_bar(std_name=std_name, xls=xls)
            rose_mat = rose_and_bar['res_rose']['chart']
            rose_pic = pic_transfer.mat_to_pil_img(rose_mat)
            rose_pic = rose_pic.resize(
                (640, 640 * rose_pic.size[1] // rose_pic.size[0]))
            rose_pic = rose_pic.crop((0, 0, 620, 640))
            bg.paste(rose_pic, (421, 1890))

            rose_data = rose_and_bar['res_rose']['data']

            #柱形图
            # bar_mat=rose_and_bar['res_bar']['chart']
            # bar_pic=pic_transfer.mat_to_pil_img(bar_mat)
            # bar_pic=bar_pic.resize((640,640*rose_pic.size[1]//rose_pic.size[0]))
            # bar_pic=bar_pic.crop((0,0,620,640))
            # bg.paste(bar_pic,(1460,1890))

            #雷达图
            radar_mat = rose_and_bar['res_radar']['chart']
            radar_pic = pic_transfer.mat_to_pil_img(radar_mat)
            radar_pic = radar_pic.resize(
                (640, 640 * radar_pic.size[1] // radar_pic.size[0]))
            # radar_pic=radar_pic.crop((0,0,620,640))
            bg.paste(radar_pic, (1460, 1890))

            #签名(图片)
            tch_sig_txt = []
            for m, tch_n in enumerate(tch_name):
                try:
                    pic_tch_sig = Image.open(
                        os.path.join(self.tch_sig_pic_dir, tch_n + '.png'))
                    pic_tch_sig = pic_tch_sig.resize(
                        (200,
                         200 * pic_tch_sig.size[1] // pic_tch_sig.size[0]))
                    r_sig, g_sig, b_sib, a_sig = pic_tch_sig.split()
                    bg.paste(pic_tch_sig, (950 + m * 1000, 3015),
                             mask=pic_tch_sig)
                except FileNotFoundError as e:
                    tch_sig_txt.append([m, tch_n])
                    # print(tch_n,e)

            #最高和高低的两个能力名称
            abl_btm = [rose_data[0][0], rose_data[1][0]]
            abl_top = [rose_data[3][0], rose_data[4][0]]

            #文字部分
            #标题
            draw.text((int(1020 * k), int(101 * k)),
                      '科学机器人课',
                      fill='#7197b4',
                      font=self.font('方正韵动粗黑简', int(78 * k)))
            draw.text((int(890 * k), int(220 * k)),
                      '课程学习报告',
                      fill='#7197b4',
                      font=self.font('方正韵动粗黑简', int(120 * k)))
            #姓名班级
            ftsz_name = 120
            x_name = (2481 - ftsz_name * len(std_name)) // 2
            draw.text((int(x_name), int(421 * k)),
                      std_name,
                      fill='#3e3a39',
                      font=self.font('汉仪字酷堂义山楷w', int(ftsz_name * k)))
            # draw.text((int(400*k*0.9),int(182*k*0.9)),std_school+' '+std_class,fill='#6C8466',font=self.font('汉仪字酷堂义山楷w',int(30*k)))

            #课程信息

            # print(total_crs)
            prd = total_crs['上课日期'].apply(
                lambda x: x.strftime('%Y-%m-%d')).tolist()
            mth_start = prd[0].split('-')[0] + '年' + prd[0].split('-')[1] + '月'
            mth_end = prd[-1].split('-')[0] + '年' + prd[-1].split('-')[1] + '月'
            prd_txt = '{}-{}'.format(mth_start, mth_end)
            std_crs_finish_number = len(std_crs) if len(std_crs) <= 16 else 16

            draw.text((930, 580),
                      prd_txt,
                      fill='#7197b4',
                      font=self.font('方正韵动粗黑简', int(50 * k)))
            # draw.text((820,730),'在大智小超科学实验室学习',fill='#7197b4',font=self.font('方正韵动粗黑简',int(50*k)))
            draw.text((700, 670),
                      '完成了{}节科学机器人课程的学习'.format(std_crs_finish_number),
                      fill='#7197b4',
                      font=self.font('方正韵动粗黑简', int(72 * k)))
            draw.text((980, 1594),
                      '学习情况总结',
                      fill='#7197b4',
                      font=self.font('优设标题', int(90 * k)))
            #能力描述
            # format(abl_top[0],abl_top[1],abl_btm[0],abl_btm[1])
            # draw.text((1790,2625),'你现在最棒的能力',fill='#9f9c9c',font=self.font('优设标题',int(50*k)))
            # draw.text((1750,2905),'还可以再提升的能力',fill='#9f9c9c',font=self.font('优设标题',int(50*k)))
            # draw.text((1750,2715),'• '+abl_top[1],fill=rose_data[-1][2],font=self.font('微软雅黑',int(70*k)))
            # draw.text((1750,2995),'• '+abl_btm[0],fill=rose_data[0][2],font=self.font('微软雅黑',int(70*k)))

            # composing.put_txt_img(draw=draw,tt='• '+abl_top[0]+'\n'+'• '+abl_top[1],total_dis=int(800*k*0.95), \
            #                     xy=[1750,2705],dis_line=int(23*k),fill='#7197b4', \
            #                     font_name='微软雅黑',font_size=40,addSPC="add_2spaces")
            # composing.put_txt_img(draw=draw,tt='• '+abl_btm[0]+'\n'+'• '+abl_btm[1],total_dis=int(800*k*0.95), \
            #                     xy=[1750,2995],dis_line=int(23*k),fill='#7197b4', \
            #                     font_name='微软雅黑',font_size=40,addSPC="add_2spaces")

            #评语
            #左右标题
            draw.text((608, 1764),
                      '技能成长',
                      fill='#7197b4',
                      font=self.font('优设标题', int(80 * k)))
            draw.text((1598, 1764),
                      '社会能力成长',
                      fill='#7197b4',
                      font=self.font('优设标题', int(80 * k)))
            draw.text((698, 3034),
                      '上课老师:',
                      fill='#7197b4',
                      font=self.font('优设标题', int(50 * k)))
            draw.text((1618, 3034),
                      '特约心理老师:',
                      fill='#7197b4',
                      font=self.font('优设标题', int(50 * k)))


            composing.put_txt_img(draw=draw,tt=comments_for_std,total_dis=int(980*k*0.95), \
                                xy=[248,2607],dis_line=int(23*k),fill='#3e3a39', \
                                font_name='丁永康硬笔楷书',font_size=font_size_cmt,addSPC="add_2spaces")

            composing.put_txt_img(draw=draw,tt=comments_for_std_psycho,total_dis=int(980*k*0.95), \
                                xy=[1313,2607],dis_line=int(23*k),fill='#3e3a39', \
                                font_name='丁永康硬笔楷书',font_size=font_size_cmt,addSPC="add_2spaces")

            #签名(如无图片,则用文字)
            #上课
            # draw.text((950,3035),tch_name[0]+'老师',fill='#3e3a39',font=self.font('丁永康硬笔楷书',int(50*k)))
            draw.text((950, 3100),
                      cmt_date[0:4] + '.' + cmt_date[4:6] + '.' + cmt_date[6:],
                      fill='#3e3a39',
                      font=self.font('丁永康硬笔楷书', int(40 * k)))
            #心理
            # draw.text((1950,3035),tch_name[1]+'老师',fill='#3e3a39',font=self.font('丁永康硬笔楷书',int(50*k)))
            draw.text((1950, 3100),
                      cmt_date[0:4] + '.' + cmt_date[4:6] + '.' + cmt_date[6:],
                      fill='#3e3a39',
                      font=self.font('丁永康硬笔楷书', int(40 * k)))

            if tch_sig_txt:
                for tch_sig_t in tch_sig_txt:
                    if tch_sig_t[0] == 0:
                        draw.text((950, 3035),
                                  tch_sig_t[1] + '老师',
                                  fill='#3e3a39',
                                  font=self.font('丁永康硬笔楷书', int(50 * k)))
                    elif tch_sig_t[0] == 1:
                        draw.text((1950, 3035),
                                  tch_sig_t[1] + '老师',
                                  fill='#3e3a39',
                                  font=self.font('丁永康硬笔楷书', int(50 * k)))
                    else:
                        print('没有该老师签名,请检查。')

            #slogan
            draw.text((600, 3300),
                      '让孩子从小玩科学,爱科学,学科学。',
                      fill='#c23030',
                      font=self.font('楷体', int(82 * k)))

            # draw.text((int(380*k),int((y_logo+10))), '长按二维码 → \n关注视频号 →', fill = '#8E9184',font=self.font('微软雅黑',25))

            bg = bg.convert('RGB')
            savename = os.path.join(
                self.term_pic_dir,
                std_name + '-' + cmt_date + '-' + term + '-课程学习报告.jpg')
            if not os.path.exists(self.term_pic_dir):
                os.makedirs(self.term_pic_dir)
            # savename=os.path.join('e:/temp/',std_name+'.jpg')
            bg.save(savename, quality=90, subsampling=0)
            # bg.save(savename,quality=95,dpi=(300,300))
            # bg.show()
            print('图片保存完成,保存路径:{}'.format(savename))

        draw_crs()