new
parent
c3cf2a4531
commit
bf19e2d469
|
@ -1,11 +1,40 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<script type="text/javascript" src="../js/vue.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!--
|
||||
1.vue中的数据代理:
|
||||
通过vm对象来代理data对象中属性的操作(读-getter/写-setter)
|
||||
2.vue中数据代理的好处:
|
||||
更加方便的操作data中的数据
|
||||
3.基本原理:
|
||||
通过Object.defineProperty()把data对象中所有属性添加到vm上
|
||||
为每一个添加到vm上的属性,都指定一个getter/setter
|
||||
在getter/setter内部去操作(读/写)data中对应的属性
|
||||
-->
|
||||
<div id="root">
|
||||
<h2>学校名称: {{name}}</h2>
|
||||
<h2>学校地址: {{address}}</h2>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<script type="text/javascript">
|
||||
Vue.config.productionTip = false
|
||||
|
||||
const vm = new Vue({
|
||||
el:'#root',
|
||||
data:{
|
||||
name:'nihao',
|
||||
address: "where"
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
</html>
|
87
全员营销奖励.py
87
全员营销奖励.py
|
@ -1,30 +1,77 @@
|
|||
import textwrap
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
import pandas as pd
|
||||
|
||||
def add_text(text_item):
|
||||
|
||||
def add_text(image, font_path, save_name):
|
||||
# 打开图片
|
||||
image = Image.open(r"D:\下载\员工奖励bg.png")
|
||||
for key, value in text_item.items():
|
||||
i = 1
|
||||
for text in value:
|
||||
if type(text[0]) == str:
|
||||
image = Image.open(r'D:\cori\员工奖励bg1.png')
|
||||
draw = ImageDraw.Draw(image)
|
||||
font_path_title = r'D:\onedrive\Documents\WeChat Files\fumeng0108\FileStorage\File\2020-05\思源黑体(7款)\思源黑体(7款)\SourceHanSansCN-Bold.otf'
|
||||
font_path_content = r'D:\onedrive\Documents\WeChat Files\fumeng0108\FileStorage\File\2020-05\思源黑体(7款)\思源黑体(7款)\SourceHanSansCN-Regular.otf'
|
||||
font_size_title = 36
|
||||
font_size_content = 25
|
||||
|
||||
# 创建一个可编辑的图片副本
|
||||
draw = ImageDraw.Draw(image)
|
||||
font_title = ImageFont.truetype(font_path_title, font_size_title)
|
||||
font_content = ImageFont.truetype(font_path_content, font_size_content)
|
||||
i += 1
|
||||
# print(text)
|
||||
# print(text[0])
|
||||
# print(text[1])
|
||||
# print(text[2])
|
||||
# print(text[3])
|
||||
# print(text[4])
|
||||
# print(text[5])
|
||||
save_name = key + text[0] + str(i) + '.png'
|
||||
print(save_name)
|
||||
# 获取文本大小
|
||||
text_width1, text_height1 = draw.textsize(text[0], font_title)
|
||||
text_width2, text_height2 = draw.textsize(text[1], font_content)
|
||||
text_width3, text_height3 = draw.textsize(text[2], font_content)
|
||||
text_width4, text_height4 = draw.textsize(str(text[3]), font_content)
|
||||
text_width5, text_height5 = draw.textsize(str(text[4]), font_content)
|
||||
|
||||
# 设置要添加的文本
|
||||
text = "手机银行"
|
||||
# 计算文本的位置使其居中
|
||||
image_width, a = image.size
|
||||
text_x1 = (image_width - text_width1) / 2
|
||||
text_x2 = (image_width - text_width2) / 2
|
||||
text_x3 = (image_width - text_width3) / 2
|
||||
text_x4 = (image_width - text_width4) / 2
|
||||
text_x5 = (image_width - text_width5) / 2
|
||||
|
||||
# 选择字体和字号
|
||||
font_path = r"C:\Users\Cori\OneDrive\Documents\WeChat Files\fumeng0108\FileStorage\File\2020-05\思源黑体(7款)\思源黑体(7款)\SourceHanSansCN-Bold.otf"
|
||||
font = ImageFont.truetype(font_path, 36)
|
||||
# 在图片上添加文本
|
||||
draw.text((text_x1, 19), text[0], font=font_title, fill="#AA1017")
|
||||
draw.text((text_x2, 186), text[1], font=font_content, fill="#FAC79B")
|
||||
draw.text((text_x3, 346), text[2], font=font_content, fill="#FAC79B")
|
||||
draw.text((text_x4, 505), str(text[3]), font=font_content, fill="#FAC79B")
|
||||
draw.text((text_x5, 664), str(text[4]), font=font_content, fill="#FAC79B")
|
||||
# text_width = 22
|
||||
# wrapped_text = textwrap.wrap(text[5], width=text_width)
|
||||
# pos = (36, 868)
|
||||
# leading = 42
|
||||
# for i, line in enumerate(wrapped_text):
|
||||
# draw.text((pos[0], leading * i + pos[1]), line, font=font_content, fill="#FAC79B")
|
||||
|
||||
# 获取文本大小
|
||||
text_width, text_height = draw.textsize(text, font)
|
||||
# 保存修改后的图片
|
||||
image.save(r"D:\cori\员工营销" + "/" + save_name)
|
||||
|
||||
# 计算文本的位置使其居中
|
||||
image_width, image_height = image.size
|
||||
text_x = (image_width - text_width) / 2
|
||||
text_y = 19
|
||||
def get_data(file_path):
|
||||
# 读取Excel文件
|
||||
excel_data = pd.read_excel(file_path, sheet_name=None)
|
||||
|
||||
# 在图片上添加文本
|
||||
draw.text((text_x, text_y), text, font=font, fill="#AA1017")
|
||||
# 将每个sheet的数据转换成字典
|
||||
data_dict = {}
|
||||
for sheet_name, sheet_data in excel_data.items():
|
||||
data_dict[sheet_name] = sheet_data.values.tolist()
|
||||
|
||||
# 保存修改后的图片
|
||||
image.save(r"D:\下载\员工营销\1bg.png")
|
||||
return data_dict
|
||||
# print(data_dict['全员'][0])
|
||||
|
||||
file_path = r'D:\cori\2024年全员营销奖励一张表 - 营销助手展示-拆分.xlsx'
|
||||
text_item = get_data(file_path)
|
||||
|
||||
add_text(text_item, )
|
Loading…
Reference in New Issue