feat : 代码梳理 移除所有敏感密钥 通过环境变量方式配置
All checks were successful
git commit AiDA python develop 分支构建部署 / scheduled_deploy (push) Has been skipped
All checks were successful
git commit AiDA python develop 分支构建部署 / scheduled_deploy (push) Has been skipped
This commit is contained in:
33
app/service/design_fast/model_process_service.py
Normal file
33
app/service/design_fast/model_process_service.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import io
|
||||
|
||||
from minio import Minio
|
||||
from app.core.config import settings
|
||||
|
||||
from app.service.utils.new_oss_client import oss_get_image, oss_upload_image
|
||||
|
||||
minio_client = Minio(settings.MINIO_URL, access_key=settings.MINIO_ACCESS, secret_key=settings.MINIO_SECRET, secure=settings.MINIO_SECURE)
|
||||
|
||||
|
||||
def model_transpose(image_path):
|
||||
bucket = image_path.split("/", 1)[0]
|
||||
object_name = image_path.split("/", 1)[1]
|
||||
new_object_name = f'{object_name[:object_name.rfind(".")]}.png'
|
||||
image = oss_get_image(oss_client=minio_client, bucket=bucket, object_name=object_name, data_type="PIL")
|
||||
image = image.convert("RGBA")
|
||||
data = image.getdata()
|
||||
#
|
||||
new_data = []
|
||||
for item in data:
|
||||
if item[0] >= 256 and item[1] >= 256 and item[2] >= 256:
|
||||
new_data.append((255, 255, 255, 0))
|
||||
else:
|
||||
new_data.append(item)
|
||||
image.putdata(new_data)
|
||||
|
||||
image_data = io.BytesIO()
|
||||
image.save(image_data, format='PNG')
|
||||
image_data.seek(0)
|
||||
image_bytes = image_data.read()
|
||||
oss_upload_image(oss_client=minio_client, bucket=bucket, object_name=new_object_name, image_bytes=image_bytes)
|
||||
image_path = f"{bucket}/{new_object_name}"
|
||||
return image_path
|
||||
Reference in New Issue
Block a user