design design batch

This commit is contained in:
zhouchengrong
2024-12-11 11:06:20 +08:00
parent 2c0a7729b8
commit e6f0ee7f3a
17 changed files with 281 additions and 26 deletions

View File

@@ -0,0 +1,26 @@
from PIL import Image
def sketch_to_transparent(image, mask, transparency):
# 打开原始图片
image = image.convert("RGBA")
# 打开mask图片假设mask图片是灰度图白色区域为要处理的区域黑色区域为保留的区域
mask = Image.fromarray(mask)
# 根据透明度调整因子将透明度转换为0-255之间的值
alpha_value = int((1 - transparency) * 255.0)
# 获取图片的像素数据
image_pixels = image.load()
mask_pixels = mask.load()
width, height = image.size
for y in range(height):
for x in range(width):
# 如果mask区域对应的像素为白色值大于128这里假设白色为要处理的区域可根据实际情况调整
if mask_pixels[x, y] > 128:
r, g, b, a = image_pixels[x, y]
image_pixels[x, y] = (r, g, b, alpha_value)
return image