图片相关路径整合

This commit is contained in:
SlyAimer 2025-02-06 12:33:59 +08:00
parent 31103cdc2a
commit 8b9348661e
110 changed files with 65 additions and 31 deletions

2
bot.py
View file

@ -7,7 +7,7 @@ nonebot.init()
driver = nonebot.get_driver()
driver.register_adapter(QQAdapter) # 注册QQ适配器
nonebot.load_from_toml("pyproject.toml")
logger.add("error.log", level="ERROR", format=default_format, rotation="1 week")
logger.add("src/resources/log/error.log", level="ERROR", format=default_format, rotation="1 week")
from src.my_sqlite.data_init.db_connect import disconnect, init
driver.on_startup(init)

View file

@ -1,6 +1,4 @@
from pathlib import Path
import nonebot
from collections import defaultdict
from pydantic import BaseModel

View file

@ -1,5 +1,20 @@
import os
from pathlib import Path
path = os.getcwd()+'/src/resources/image'
#塔罗牌图片路径
image_local_qq_image_path = path+'/qq_image'
#个人图片路径
image_local_path= path+"/MaoYuNa"
#塔罗牌图片路径
tarots_img_path = path+'/tarot/TarotImages/'
#摸摸头图片路径
rua_png = path+'/rua/'
# 图片路径
IMAGE_PATH = Path() / "resources" / "image"
# 语音路径

View file

@ -1,8 +1,6 @@
image:
app_id: "<KEY>"
bot_account: "<KEY>"
image_local_qq_image_path: "src/image/qq_image"
image_local_path: "src/image/MaoYuNa"
#SMMS图床相关配置
smms_token: "<KEY>" # sm.ms图床的token
smms_image_upload_history: "https://sm.ms/api/v2/upload_history" # sm.ms图床获取上传图片历史API地址

View file

@ -2,12 +2,13 @@ import os
import yaml
import random
import requests
from PIL import Image, ImageDraw
from PIL import Image, ImageDraw,ImageFont
from src.configs.path_config import image_local_path,image_local_qq_image_path,rua_png
with open(os.getcwd() +'/src/image/config/image.yaml', 'r', encoding='utf-8') as f:
image = yaml.load(f.read(), Loader=yaml.FullLoader).get('image')
image_local_path = image.get('image_local_path')
image_local_qq_image_path = image.get('image_local_qq_image_path')
# image_local_path = image.get('image_local_path')
# image_local_qq_image_path = image.get('image_local_qq_image_path')
smms_token = image.get('smms_token')
smms_image_upload_history = image.get('smms_image_upload_history')
ju_he_token = image.get('ju_he_token')
@ -15,26 +16,26 @@ with open(os.getcwd() +'/src/image/config/image.yaml', 'r', encoding='utf-8') as
app_id = image.get('app_id')
bot_account = image.get('bot_account')
qq_image_save__path = os.getcwd()+'/'+image_local_qq_image_path
# qq_image_save__path = os.getcwd()+'/'+image_local_qq_image_path
"""本地图片"""
def get_image_names():
image_extensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp'] # 定义常见的图片文件扩展名
image_names = []
for root, dirs, files in os.walk(os.getcwd()+'/'+image_local_path):
for root, dirs, files in os.walk(image_local_path):
for file in files:
if any(file.endswith(ext) for ext in image_extensions): # 检查文件是否是图片文件
image_names.append(file)
random.choice(image_names) # 随机选取一张图片
local_image_path = os.getcwd() + '/' + image_local_path + '/' + random.choice(image_names) # 随机选取一张图片的路径
local_image_path = image_local_path + '/' + random.choice(image_names) # 随机选取一张图片的路径
return local_image_path
"""获取QQ头像"""
def download_qq_image(member_open_id):
if not os.path.exists(qq_image_save__path):
os.makedirs(qq_image_save__path)
if not os.path.exists(image_local_qq_image_path):
os.makedirs(image_local_qq_image_path)
save_path = qq_image_save__path + '/' + member_open_id + '.jpg'
save_path = image_local_qq_image_path + '/' + member_open_id + '.jpg'
size = 640 #尺寸 40、100、140、640
url = f"https://q.qlogo.cn/qqapp/{app_id}/{member_open_id}/{size}"
response = requests.get(url) # 发送 GET 请求获取图片资源
@ -45,11 +46,11 @@ def download_qq_image(member_open_id):
"""获取QQ头像"""
def download_qq_image_by_account(account):
if not os.path.exists(qq_image_save__path):
os.makedirs(qq_image_save__path)
if not os.path.exists(image_local_qq_image_path):
os.makedirs(image_local_qq_image_path)
if account is None:
account = bot_account
save_path = qq_image_save__path + '/' + account + '.jpg'
save_path = image_local_qq_image_path + '/' + account + '.jpg'
size = 640 # 尺寸 40、100、140、640
url = f"https://q2.qlogo.cn/headimg_dl?dst_uin={account}&spec={size}"
response = requests.get(url) # 发送 GET 请求获取图片资源
@ -102,13 +103,11 @@ class rua():
return rua_png1
def add_gif(self):
# 获取素材路径
png_dir = os.getcwd() +'/src/image/rua/'
# 获取素材列表
pst = os.listdir(png_dir)
pst = os.listdir(rua_png)
for i in range(len(pst)):
pst[i] = png_dir + pst[i]
pst[i] = rua_png + pst[i]
# 预调试好的参数,传入素材列表
jd = [[90, 90, 5, pst[0]],
@ -139,9 +138,31 @@ class rua():
gifs.append(self.add_png(jd[i]))
# 文件名,是否保存所有,图片列表,fps/ms
gifs[0].save(os.getcwd() + '/' + image_local_qq_image_path + '/rua.gif', "GIF", save_all=True, append_images=gifs, duration=35, loop=0)
gifs[0].save(image_local_qq_image_path + '/rua.gif', "GIF", save_all=True, append_images=gifs, duration=35, loop=0)
self.author.close()
return os.getcwd() + '/' + image_local_qq_image_path + '/rua.gif'
return image_local_qq_image_path + '/rua.gif'
"""
图文合成
"""
def add_text_to_image(image_path, text, output_path, font_size):
# 打开图片
image = Image.open(image_path)
# 创建一个可用于绘制的对象
draw = ImageDraw.Draw(image)
# 设置字体和字体大小
font = ImageFont.truetype("arial.ttf", font_size) # 这里使用 Arial 字体,你可以替换为其他字体文件路径
# 设置文本的位置和颜色
position = (50, 50)
text_color = (255, 0, 0) # 红色
# 在图片上绘制文本
draw.text(position, text, font=font, fill=text_color)
# 保存合成后的图片
image.save(output_path)
print(f"合成后的图片已保存到 {output_path}")
if __name__ == '__main__':
@ -149,4 +170,8 @@ if __name__ == '__main__':
print(get_juhe_image_url())
print(get_image_names())
file_path = '8A91A2F3BE5B5AF3FEC97FB5AA6D9B38.jpg'
au = rua(file_path).add_gif()
au = rua(file_path).add_gif()
image_path = "Justice.jpg"
text = "Hello, World!"
output_path = "output.jpg"
add_text_to_image(image_path, text, output_path, font_size=48)

View file

@ -4,9 +4,7 @@ from datetime import datetime
from tortoise import fields
from typing_extensions import Self
from src.my_sqlite.data_init.db_connect import Model
tarots_img_path = os.getcwd()+'/src/image/tarot/TarotImages/'
from src.configs.path_config import tarots_img_path
class MajorArcanaLog:

View file

@ -51,7 +51,7 @@ class UserList(Model):
"""
user_table = await cls.filter(user_id=user_id, group_id=group_id).first()
if user_table:
user_table.use_time = datetime.now().date()
user_table.last_used_time = datetime.now().date()
await user_table.save()
else:
await cls.create(user_id=user_id,group_id=group_id,last_used_time=datetime.now().date())

View file

@ -92,7 +92,7 @@ async def github_repo():
content = "三叶草bot仓库地址\n一起来搭个机器人吧😆"
msg = Message([
MessageSegment.file_image(Path("src/image/github_repo/SanYeCao-Nonebot3.png")),
MessageSegment.file_image(Path("src/resources/image/github_repo/SanYeCao-Nonebot3.png")),
MessageSegment.text(content),
])
await repository.finish(msg)

View file

@ -24,7 +24,7 @@ async def get_cf_rounds():
if matches["phase"] == "FINISHED":
break
cf_image_path = './src/image/codeforces/cfContestQR.png'
cf_image_path = './src/resources/image/codeforces/cfContestQR.png'
msg = Message([
MessageSegment.file_image(Path(cf_image_path)),
MessageSegment.text(all_matches),

Binary file not shown.

View file

Before

Width:  |  Height:  |  Size: 3.4 MiB

After

Width:  |  Height:  |  Size: 3.4 MiB

View file

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View file

Before

Width:  |  Height:  |  Size: 799 KiB

After

Width:  |  Height:  |  Size: 799 KiB

View file

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

View file

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View file

Before

Width:  |  Height:  |  Size: 386 KiB

After

Width:  |  Height:  |  Size: 386 KiB

View file

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

View file

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

View file

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

View file

Before

Width:  |  Height:  |  Size: 686 KiB

After

Width:  |  Height:  |  Size: 686 KiB

View file

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View file

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

View file

Before

Width:  |  Height:  |  Size: 2.2 MiB

After

Width:  |  Height:  |  Size: 2.2 MiB

View file

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

View file

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB

View file

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View file

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

View file

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View file

Before

Width:  |  Height:  |  Size: 1.8 MiB

After

Width:  |  Height:  |  Size: 1.8 MiB

View file

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View file

Before

Width:  |  Height:  |  Size: 409 KiB

After

Width:  |  Height:  |  Size: 409 KiB

View file

Before

Width:  |  Height:  |  Size: 734 KiB

After

Width:  |  Height:  |  Size: 734 KiB

View file

Before

Width:  |  Height:  |  Size: 913 KiB

After

Width:  |  Height:  |  Size: 913 KiB

View file

Before

Width:  |  Height:  |  Size: 1.5 MiB

After

Width:  |  Height:  |  Size: 1.5 MiB

View file

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View file

Before

Width:  |  Height:  |  Size: 765 KiB

After

Width:  |  Height:  |  Size: 765 KiB

View file

Before

Width:  |  Height:  |  Size: 806 KiB

After

Width:  |  Height:  |  Size: 806 KiB

View file

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View file

Before

Width:  |  Height:  |  Size: 891 KiB

After

Width:  |  Height:  |  Size: 891 KiB

View file

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 54 KiB

View file

Before

Width:  |  Height:  |  Size: 158 KiB

After

Width:  |  Height:  |  Size: 158 KiB

View file

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

View file

Before

Width:  |  Height:  |  Size: 231 KiB

After

Width:  |  Height:  |  Size: 231 KiB

View file

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View file

Before

Width:  |  Height:  |  Size: 5 KiB

After

Width:  |  Height:  |  Size: 5 KiB

View file

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View file

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View file

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View file

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View file

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View file

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View file

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View file

Before

Width:  |  Height:  |  Size: 5 KiB

After

Width:  |  Height:  |  Size: 5 KiB

View file

Before

Width:  |  Height:  |  Size: 1 MiB

After

Width:  |  Height:  |  Size: 1 MiB

View file

Before

Width:  |  Height:  |  Size: 1 MiB

After

Width:  |  Height:  |  Size: 1 MiB

View file

Before

Width:  |  Height:  |  Size: 1 MiB

After

Width:  |  Height:  |  Size: 1 MiB

View file

Before

Width:  |  Height:  |  Size: 1 MiB

After

Width:  |  Height:  |  Size: 1 MiB

View file

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

View file

Before

Width:  |  Height:  |  Size: 2.7 MiB

After

Width:  |  Height:  |  Size: 2.7 MiB

View file

Before

Width:  |  Height:  |  Size: 2.6 MiB

After

Width:  |  Height:  |  Size: 2.6 MiB

View file

Before

Width:  |  Height:  |  Size: 2.6 MiB

After

Width:  |  Height:  |  Size: 2.6 MiB

View file

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View file

Before

Width:  |  Height:  |  Size: 1.5 MiB

After

Width:  |  Height:  |  Size: 1.5 MiB

View file

Before

Width:  |  Height:  |  Size: 2.8 MiB

After

Width:  |  Height:  |  Size: 2.8 MiB

View file

Before

Width:  |  Height:  |  Size: 2.7 MiB

After

Width:  |  Height:  |  Size: 2.7 MiB

View file

Before

Width:  |  Height:  |  Size: 2.8 MiB

After

Width:  |  Height:  |  Size: 2.8 MiB

View file

Before

Width:  |  Height:  |  Size: 2.8 MiB

After

Width:  |  Height:  |  Size: 2.8 MiB

View file

Before

Width:  |  Height:  |  Size: 2.7 MiB

After

Width:  |  Height:  |  Size: 2.7 MiB

View file

Before

Width:  |  Height:  |  Size: 2.6 MiB

After

Width:  |  Height:  |  Size: 2.6 MiB

View file

Before

Width:  |  Height:  |  Size: 2.8 MiB

After

Width:  |  Height:  |  Size: 2.8 MiB

View file

Before

Width:  |  Height:  |  Size: 2.8 MiB

After

Width:  |  Height:  |  Size: 2.8 MiB

View file

Before

Width:  |  Height:  |  Size: 2.8 MiB

After

Width:  |  Height:  |  Size: 2.8 MiB

View file

Before

Width:  |  Height:  |  Size: 2.8 MiB

After

Width:  |  Height:  |  Size: 2.8 MiB

View file

Before

Width:  |  Height:  |  Size: 2.7 MiB

After

Width:  |  Height:  |  Size: 2.7 MiB

View file

Before

Width:  |  Height:  |  Size: 2.6 MiB

After

Width:  |  Height:  |  Size: 2.6 MiB

View file

Before

Width:  |  Height:  |  Size: 2.8 MiB

After

Width:  |  Height:  |  Size: 2.8 MiB

View file

Before

Width:  |  Height:  |  Size: 2.8 MiB

After

Width:  |  Height:  |  Size: 2.8 MiB

View file

Before

Width:  |  Height:  |  Size: 2.7 MiB

After

Width:  |  Height:  |  Size: 2.7 MiB

View file

Before

Width:  |  Height:  |  Size: 2.9 MiB

After

Width:  |  Height:  |  Size: 2.9 MiB

View file

Before

Width:  |  Height:  |  Size: 2.7 MiB

After

Width:  |  Height:  |  Size: 2.7 MiB

View file

Before

Width:  |  Height:  |  Size: 2.5 MiB

After

Width:  |  Height:  |  Size: 2.5 MiB

View file

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View file

Before

Width:  |  Height:  |  Size: 1.5 MiB

After

Width:  |  Height:  |  Size: 1.5 MiB

View file

Before

Width:  |  Height:  |  Size: 2.6 MiB

After

Width:  |  Height:  |  Size: 2.6 MiB

View file

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View file

Before

Width:  |  Height:  |  Size: 1.5 MiB

After

Width:  |  Height:  |  Size: 1.5 MiB

View file

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View file

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View file

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View file

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View file

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View file

Before

Width:  |  Height:  |  Size: 1.5 MiB

After

Width:  |  Height:  |  Size: 1.5 MiB

View file

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View file

Before

Width:  |  Height:  |  Size: 1.5 MiB

After

Width:  |  Height:  |  Size: 1.5 MiB

View file

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View file

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

View file

Before

Width:  |  Height:  |  Size: 1.5 MiB

After

Width:  |  Height:  |  Size: 1.5 MiB

View file

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB

View file

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View file

Before

Width:  |  Height:  |  Size: 1.5 MiB

After

Width:  |  Height:  |  Size: 1.5 MiB

Some files were not shown because too many files have changed in this diff Show more