save code

This commit is contained in:
xsl
2026-02-27 22:56:59 +08:00
parent 73e356def7
commit 339e7dc1f6
5 changed files with 207 additions and 16 deletions
+10 -7
View File
@@ -513,10 +513,10 @@ def image_to_base64(file_path, with_head = True):
def upload_to_oss(image_path, object_name=None):
# 配置信息(替换为你的实际信息)
access_key_id = 'LTAI5tB9t2RH6f1drSLvVLLZ'
access_key_secret = '91uzPI1RAFHN7n3Y6TJDGFP8w0dG1R'
access_key_id = 'LTAI5tGp1sLzedqxihcNC1eb'
access_key_secret = 'IFZE1b8YYreCP6zfA6GaZ9uBT678qO'
endpoint = 'oss-cn-beijing.aliyuncs.com' # 替换为你的Endpoint
bucket_name = 'llyz'
bucket_name = 'xiangsilian'
# 创建Bucket实例
auth = oss2.Auth(access_key_id, access_key_secret)
@@ -615,7 +615,7 @@ def process_change_banana(human_filename, cloth_filename, output_format):
jpg_path_name = f'{APP_ROOT}/static/imgs/{jpg_name}'
image.save(jpg_path_name, quality=90)
upload_to_oss(jpg_path_name, jpg_name)
https_url = f'https://llyz.oss-cn-beijing.aliyuncs.com/{jpg_name}'
https_url = f'https://xiangsilian.oss-cn-beijing.aliyuncs.com/{jpg_name}'
if img_data:
if 'base64' in output_format:
@@ -658,7 +658,7 @@ def process_change_cloth(human_filename, cloth_filename, output_format, img_url,
out_human_jpg_path_name = f'{APP_ROOT}/static/imgs/{out_human_jpg_name}'
out_human_image.save(out_human_jpg_path_name, quality=90)
upload_to_oss(out_human_jpg_path_name, out_human_jpg_name) # 第二个参数可选,指定OSS上的路径
out_human_https_url = f'https://llyz.oss-cn-beijing.aliyuncs.com/{out_human_jpg_name}'
out_human_https_url = f'https://xiangsilian.oss-cn-beijing.aliyuncs.com/{out_human_jpg_name}'
print(f"生成的第一步图片 HTTPS URL: {out_human_https_url}")
image = Image.open(f'{APP_ROOT}/../output/{out_put_name}')
@@ -668,7 +668,7 @@ def process_change_cloth(human_filename, cloth_filename, output_format, img_url,
upload_to_oss(jpg_path_name, jpg_name) # 第二个参数可选,指定OSS上的路径
https_url = f'https://llyz.oss-cn-beijing.aliyuncs.com/{jpg_name}'
https_url = f'https://xiangsilian.oss-cn-beijing.aliyuncs.com/{jpg_name}'
print(f"生成的HTTPS URL: {https_url}")
out_befor_kuzi_url = https_url
@@ -686,7 +686,7 @@ def process_change_cloth(human_filename, cloth_filename, output_format, img_url,
image.save(jpg_path_name, quality=90)
upload_to_oss(jpg_path_name, jpg_name) # 第二个参数可选,指定OSS上的路径
https_url = f'https://llyz.oss-cn-beijing.aliyuncs.com/{jpg_name}'
https_url = f'https://xiangsilian.oss-cn-beijing.aliyuncs.com/{jpg_name}'
print(f"生成的加上换裤子的 HTTPS URL: {https_url}")
@@ -755,6 +755,8 @@ def do_change_cloth():
"""从 URL 下载图片"""
data = request.json
print(f"do_change_cloth input data:{data}")
human_url = data.get("human_url")
human_filename = save_image_from_url(human_url)
@@ -892,6 +894,7 @@ def change_cloth():
def change_cloth_base64():
# 获取参数
data = request.get_json()
print(f"change_cloth_base64 input data:{data}")
if not data:
return jsonify({"ret":-1, "state":-1, 'msg': 'No JSON data provided'}), 400