fix  design print防止png图片透明转黑 出现的bug,采用pil读图
This commit is contained in:
zhouchengrong
2024-06-24 15:25:32 +08:00
parent 19c0a35bce
commit 42cc2e1c51

View File

@@ -466,13 +466,11 @@ class PrintPainting(object):
bucket_name = print_dict['print_path_list'][0].split("/", 1)[0] bucket_name = print_dict['print_path_list'][0].split("/", 1)[0]
object_name = print_dict['print_path_list'][0].split("/", 1)[1] object_name = print_dict['print_path_list'][0].split("/", 1)[1]
image = oss_get_image(bucket=bucket_name, object_name=object_name, data_type="cv2") image = oss_get_image(bucket=bucket_name, object_name=object_name, data_type="PIL")
# 判断图片格式如果是RGBA 则贴在一张纯白图片上 防止透明转黑 # 判断图片格式如果是RGBA 则贴在一张纯白图片上 防止透明转黑
if image.shape[2] == 4: if image.mode == "RGBA":
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGRA2RGBA) new_background = Image.new('RGB', image.size, (255, 255, 255))
image_pil = Image.fromarray(image_rgb) new_background.paste(image, mask=image.split()[3])
new_background = Image.new('RGB', image_pil.size, (255, 255, 255))
new_background.paste(image_pil, mask=image.split()[3])
image = new_background image = new_background
print_dict['image'] = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2BGR) print_dict['image'] = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2BGR)