Open yaju1234 opened 1 month ago
Here is the full source code from io import BytesIO from aspose.psd.fileformats.psd import PsdImage from aspose.psd.fileformats.psd.layers import Layer, LayerMaskData
from PIL import Image
inputFile = "original.jpg" maskFile = "alpha.png" outputFile = "AddFileAsLayer.psd"
with open(inputFile, "rb") as file: original_image_data = file.read()
with open(maskFile, "rb") as file: mask_image_data = file.read()
img = Image.open(inputFile) mask = Image.open(maskFile).convert("L") img.putalpha(mask)
imgByteArr = BytesIO() img.save(imgByteArr, format='PNG') imgByteArr = imgByteArr.getvalue()
original_layer = Layer(BytesIO(original_image_data))
transparent_layer = Layer(BytesIO(imgByteArr))
mask_layer = Layer(BytesIO(mask_image_data)) mask_layer.is_visible = False
layer_mask = LayerMaskData() layer_mask.image_data = mask_image_data original_layer.layer_mask_data = layer_mask
psd_image = PsdImage(original_layer.width, original_layer.height)
psd_image.layers = [original_layer, mask_layer, transparent_layer]
psd_image.save(outputFile)
When creating the object layer_mask = LayerMaskData() it gives error TypeError: type has no available constructor. Please help me . I have a original image and mask image . I have added the original image in a layer and want to create a layer mask and to to add the mask image in that layer mask. But layer_mask = LayerMaskData() is not working. I am using ubuntu22.04 and python3.10