mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-08 21:15:46 +08:00
🎨 新增配置图片生成质量
, 并优化网页控制台弹窗
This commit is contained in:
parent
c1cc76abde
commit
1a94853751
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -24,4 +24,5 @@
|
||||
"python.linting.flake8CategorySeverity.W": "Warning",
|
||||
"python.linting.flake8CategorySeverity.F": "Warning",
|
||||
"python.linting.flake8CategorySeverity.E": "Warning",
|
||||
"python.analysis.autoImportCompletions": true,
|
||||
}
|
||||
|
@ -7,7 +7,9 @@ from gsuid_core.sv import SV, Plugins
|
||||
|
||||
# from gsuid_core.utils.image.image_tools import get_color_bg
|
||||
from gsuid_core.utils.fonts.fonts import core_font
|
||||
from gsuid_core.utils.plugins_config.gs_config import pic_gen_config
|
||||
|
||||
pic_quality: int = pic_gen_config.get_config('PicQuality').data
|
||||
TEXT_PATH = Path(__file__).parent / 'texture2d'
|
||||
CORE_HELP_IMG = Path(__file__).parent / 'core_help.jpg'
|
||||
|
||||
@ -223,7 +225,7 @@ async def get_help_img() -> Image.Image:
|
||||
img.save(
|
||||
CORE_HELP_IMG,
|
||||
format='JPEG',
|
||||
quality=80,
|
||||
quality=pic_quality,
|
||||
subsampling=0,
|
||||
)
|
||||
|
||||
|
@ -7,12 +7,14 @@ from PIL import Image, ImageDraw, ImageFont, ImageFilter
|
||||
from gsuid_core.data_store import get_res_path
|
||||
from gsuid_core.utils.image.convert import convert_img
|
||||
from gsuid_core.utils.image.image_tools import crop_center_img
|
||||
from gsuid_core.utils.plugins_config.gs_config import pic_gen_config
|
||||
|
||||
from .model import PluginHelp
|
||||
|
||||
cache: Dict[str, int] = {}
|
||||
MICON_PATH = Path(__file__).parent / 'icon'
|
||||
DEFAULT_ICON = MICON_PATH / '拼图.png'
|
||||
pic_quality: int = pic_gen_config.get_config('PicQuality').data
|
||||
|
||||
|
||||
def cx(w: int, x: int) -> int:
|
||||
@ -211,7 +213,7 @@ async def get_help(
|
||||
img.save(
|
||||
help_path,
|
||||
'JPEG',
|
||||
quality=89,
|
||||
quality=pic_quality,
|
||||
subsampling=0,
|
||||
)
|
||||
cache[name] = 1
|
||||
|
@ -17,6 +17,7 @@ from gsuid_core.utils.image.convert import text2pic
|
||||
from gsuid_core.utils.image.image_tools import sget
|
||||
from gsuid_core.load_template import markdown_templates
|
||||
from gsuid_core.utils.plugins_config.gs_config import (
|
||||
pic_gen_config,
|
||||
send_pic_config,
|
||||
pic_upload_config,
|
||||
core_plugins_config,
|
||||
@ -34,6 +35,8 @@ is_lf = core_plugins_config.get_config('UseCRLFReplaceLFForMD').data
|
||||
SERVER = pic_upload_config.get_config('PicUploadServer').data
|
||||
IS_UPLOAD = pic_upload_config.get_config('PicUpload').data
|
||||
|
||||
pic_quality: int = pic_gen_config.get_config('PicQuality').data
|
||||
|
||||
pclient = None
|
||||
if IS_UPLOAD:
|
||||
if SERVER == 'smms':
|
||||
@ -62,7 +65,9 @@ class MessageSegment:
|
||||
if isinstance(img, Image.Image):
|
||||
img = img.convert('RGB')
|
||||
result_buffer = BytesIO()
|
||||
img.save(result_buffer, format='PNG', quality=80, subsampling=0)
|
||||
img.save(
|
||||
result_buffer, format='PNG', quality=pic_quality, subsampling=0
|
||||
)
|
||||
img = result_buffer.getvalue()
|
||||
elif isinstance(img, bytes):
|
||||
pass
|
||||
|
@ -7,8 +7,11 @@ import aiofiles
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
from gsuid_core.utils.fonts.fonts import core_font
|
||||
from gsuid_core.utils.plugins_config.gs_config import pic_gen_config
|
||||
from gsuid_core.utils.image.image_tools import draw_center_text_by_line
|
||||
|
||||
pic_quality: int = pic_gen_config.get_config('PicQuality').data
|
||||
|
||||
|
||||
@overload
|
||||
async def convert_img(img: Image.Image, is_base64: bool = False) -> bytes: ...
|
||||
@ -41,7 +44,7 @@ async def convert_img(
|
||||
if isinstance(img, Image.Image):
|
||||
img = img.convert('RGB')
|
||||
result_buffer = BytesIO()
|
||||
img.save(result_buffer, format='JPEG', quality=90)
|
||||
img.save(result_buffer, format='JPEG', quality=pic_quality)
|
||||
res = result_buffer.getvalue()
|
||||
if is_base64:
|
||||
res = 'base64://' + b64encode(res).decode()
|
||||
|
@ -7,6 +7,7 @@ from gsuid_core.logger import logger
|
||||
from gsuid_core.data_store import get_res_path
|
||||
|
||||
from .config_default import CONIFG_DEFAULT
|
||||
from .pic_gen_config import PIC_GEN_CONIFG
|
||||
from .send_pic_config import SEND_PIC_CONIFG
|
||||
from .pic_server_config import PIC_UPLOAD_CONIFG
|
||||
from .models import (
|
||||
@ -167,3 +168,7 @@ pic_upload_config = StringConfig(
|
||||
send_pic_config = StringConfig(
|
||||
'GsCore发送图片', get_res_path() / 'send_pic_config.json', SEND_PIC_CONIFG
|
||||
)
|
||||
|
||||
pic_gen_config = StringConfig(
|
||||
'GsCore图片生成', get_res_path() / 'pic_gen_config.json', PIC_GEN_CONIFG
|
||||
)
|
||||
|
@ -1,4 +1,4 @@
|
||||
from typing import Dict, List, Union
|
||||
from typing import Dict, List, Union, Optional
|
||||
|
||||
import msgspec
|
||||
|
||||
@ -30,6 +30,16 @@ class GsListConfig(GsConfig, tag=True):
|
||||
data: List[int]
|
||||
|
||||
|
||||
class GsIntConfig(GsConfig, tag=True):
|
||||
data: int
|
||||
max_value: Optional[int] = None
|
||||
|
||||
|
||||
GSC = Union[
|
||||
GsDictConfig, GsBoolConfig, GsListConfig, GsListStrConfig, GsStrConfig
|
||||
GsDictConfig,
|
||||
GsBoolConfig,
|
||||
GsListConfig,
|
||||
GsListStrConfig,
|
||||
GsStrConfig,
|
||||
GsIntConfig,
|
||||
]
|
||||
|
9
gsuid_core/utils/plugins_config/pic_gen_config.py
Normal file
9
gsuid_core/utils/plugins_config/pic_gen_config.py
Normal file
@ -0,0 +1,9 @@
|
||||
from typing import Dict
|
||||
|
||||
from .models import GSC, GsIntConfig
|
||||
|
||||
PIC_GEN_CONIFG: Dict[str, GSC] = {
|
||||
'PicQuality': GsIntConfig(
|
||||
'图片生成质量', '设定生成图片的质量, 最高不可超过100', 85, 100
|
||||
),
|
||||
}
|
@ -109,6 +109,7 @@ def _set_Config(request: Request, data: Dict, config_name: str):
|
||||
else:
|
||||
value = data[name]
|
||||
all_config_list[config_name].set_config(name, value)
|
||||
return {"status": 0, "msg": "成功!"}
|
||||
|
||||
|
||||
@app.post('/genshinuid/setCoreConfig')
|
||||
|
@ -9,8 +9,10 @@ def get_service(body: List[Dict]):
|
||||
}
|
||||
|
||||
|
||||
def get_input_number(label: str, name: str, value: int):
|
||||
return {
|
||||
def get_input_number(
|
||||
label: str, name: str, value: int, max_value: Optional[int] = None
|
||||
):
|
||||
data = {
|
||||
'type': 'input-number',
|
||||
'label': label,
|
||||
'name': name,
|
||||
@ -19,6 +21,9 @@ def get_input_number(label: str, name: str, value: int):
|
||||
'step': 1,
|
||||
'value': value,
|
||||
}
|
||||
if max_value is not None:
|
||||
data['max'] = max_value
|
||||
return data
|
||||
|
||||
|
||||
def get_input_image_panel(label: str, name: str):
|
||||
@ -63,6 +68,10 @@ def get_button(title: str, api: Optional[Dict] = None):
|
||||
'onEvent': {'click': {'actions': []}},
|
||||
'id': 'u:2784abaa9455',
|
||||
'block': True,
|
||||
'messages': {
|
||||
'success': '成功!',
|
||||
'failed': '失败...请检查后台...',
|
||||
},
|
||||
}
|
||||
if api:
|
||||
data['onEvent']['click']['actions'].append(api)
|
||||
@ -94,15 +103,15 @@ def get_text_panel(label: str, name: str, value: str):
|
||||
|
||||
def get_alert(
|
||||
message: str,
|
||||
level: Literal["success", "warning", "info", 'danger'] = 'info',
|
||||
level: Literal['success', 'warning', 'info', 'danger'] = 'info',
|
||||
):
|
||||
return {
|
||||
"type": "alert",
|
||||
"body": message,
|
||||
"level": level,
|
||||
"showCloseButton": True,
|
||||
"showIcon": True,
|
||||
"className": "mb-2",
|
||||
'type': 'alert',
|
||||
'body': message,
|
||||
'level': level,
|
||||
'showCloseButton': True,
|
||||
'showIcon': True,
|
||||
'className': 'mb-2',
|
||||
}
|
||||
|
||||
|
||||
@ -119,14 +128,14 @@ def get_select_panel(label: str, name: str, value: str, options: List[str]):
|
||||
|
||||
def get_input_tag(label: str, name: str, value: List[str], options: List[str]):
|
||||
return {
|
||||
"type": "input-tag",
|
||||
"label": label,
|
||||
"name": name,
|
||||
"options": [{'label': option, 'value': option} for option in options],
|
||||
"id": "u:85ecb7894ccc",
|
||||
"optionsTip": "最近您使用的标签",
|
||||
"autoFill": {},
|
||||
"value": ','.join(value),
|
||||
'type': 'input-tag',
|
||||
'label': label,
|
||||
'name': name,
|
||||
'options': [{'label': option, 'value': option} for option in options],
|
||||
'id': 'u:85ecb7894ccc',
|
||||
'optionsTip': '最近您使用的标签',
|
||||
'autoFill': {},
|
||||
'value': ','.join(value),
|
||||
}
|
||||
|
||||
|
||||
@ -135,14 +144,14 @@ def get_divider():
|
||||
|
||||
|
||||
def get_empty():
|
||||
return {"body": [], "id": "u:d0bf1032034b"}
|
||||
return {'body': [], 'id': 'u:d0bf1032034b'}
|
||||
|
||||
|
||||
def get_grid_panel(content: List[Dict]):
|
||||
_data = []
|
||||
for i in content:
|
||||
if i == {"body": [], "id": "u:d0bf1032034b"} or i == {}:
|
||||
_data.append({"body": [], "id": "u:d0bf1032034b"})
|
||||
if i == {'body': [], 'id': 'u:d0bf1032034b'} or i == {}:
|
||||
_data.append({'body': [], 'id': 'u:d0bf1032034b'})
|
||||
else:
|
||||
_data.append({'body': [i]})
|
||||
|
||||
@ -161,9 +170,9 @@ def get_property(items: Union[List[Dict], Dict[str, str]], column: int = 2):
|
||||
_items = items
|
||||
|
||||
data = {
|
||||
"type": "property",
|
||||
"column": column,
|
||||
"items": _items,
|
||||
'type': 'property',
|
||||
'column': column,
|
||||
'items': _items,
|
||||
}
|
||||
return data
|
||||
|
||||
@ -171,24 +180,24 @@ def get_property(items: Union[List[Dict], Dict[str, str]], column: int = 2):
|
||||
def get_tag(
|
||||
label: str,
|
||||
color: Literal[
|
||||
"inactive", "processing", "success", "error", "active", "warning"
|
||||
] = "processing",
|
||||
displaymode: Literal["normal", "rounded"] = "normal",
|
||||
'inactive', 'processing', 'success', 'error', 'active', 'warning'
|
||||
] = 'processing',
|
||||
displaymode: Literal['normal', 'rounded'] = 'normal',
|
||||
):
|
||||
return {
|
||||
"type": "tag",
|
||||
"label": label,
|
||||
"displayMode": displaymode,
|
||||
"color": color,
|
||||
'type': 'tag',
|
||||
'label': label,
|
||||
'displayMode': displaymode,
|
||||
'color': color,
|
||||
}
|
||||
|
||||
|
||||
def get_tpl(label: str = '', value: str = ''):
|
||||
return {
|
||||
"type": "tpl",
|
||||
"tpl": value,
|
||||
"inline": False,
|
||||
"label": label,
|
||||
'type': 'tpl',
|
||||
'tpl': value,
|
||||
'inline': False,
|
||||
'label': label,
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
from gsuid_core.utils.plugins_config.gs_config import all_config_list
|
||||
from gsuid_core.utils.plugins_config.models import (
|
||||
GsIntConfig,
|
||||
GsStrConfig,
|
||||
GsBoolConfig,
|
||||
GsListStrConfig,
|
||||
@ -14,6 +15,7 @@ from gsuid_core.webconsole.create_base_panel import (
|
||||
get_input_tag,
|
||||
get_grid_panel,
|
||||
get_text_panel,
|
||||
get_input_number,
|
||||
get_select_panel,
|
||||
get_switch_panel,
|
||||
)
|
||||
@ -83,6 +85,12 @@ def get_config_page():
|
||||
else:
|
||||
_data = get_text_panel(gsc.title, config, gsc.data)
|
||||
solo_body.append(_data)
|
||||
elif isinstance(gsc, GsIntConfig):
|
||||
solo_body.append(
|
||||
get_input_number(
|
||||
gsc.title, config, gsc.data, gsc.max_value
|
||||
)
|
||||
)
|
||||
elif isinstance(gsc, GsBoolConfig):
|
||||
solo_body.append(get_switch_panel(gsc.title, config, gsc.data))
|
||||
elif isinstance(gsc, GsListStrConfig):
|
||||
|
Loading…
x
Reference in New Issue
Block a user