feat 模特预处理接口
fix
This commit is contained in:
28
app/service/design/model_process_service.py
Normal file
28
app/service/design/model_process_service.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import io
|
||||
|
||||
from app.service.utils.oss_client import oss_get_image, oss_upload_image
|
||||
|
||||
|
||||
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(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] >= 230 and item[1] >= 230 and item[2] >= 230:
|
||||
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(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