This commit is contained in:
2026-03-09 10:54:10 -07:00
parent 07b979e358
commit 041c0ebbdb
7 changed files with 1297 additions and 19 deletions

View File

@@ -4,7 +4,7 @@ import zipfile
import tempfile
import shutil
import numpy as np
from PIL import Image
from PIL import Image, ImageChops
import xml.etree.ElementTree as ET
NUM_LAYERS = 4
@@ -40,14 +40,15 @@ def build_stack_xml(w, h, groups):
)
for layer in group["layers"]:
layer_attrs = {
"name": layer["name"],
"src": layer["src"],
"opacity": "1.0"
}
ET.SubElement(
group_el,
"layer",
{
"name": layer["name"],
"src": layer["src"],
"opacity": "1.0"
}
layer_attrs
)
return ET.tostring(image, encoding="utf-8", xml_declaration=True)
@@ -74,24 +75,22 @@ def build_ora(input_png, output_ora):
group_layers = []
base_path = f"data/layer_{i}.png"
base.save(os.path.join(tmp, base_path))
group_layers.append({
"name": "base",
"src": base_path
})
for j in range(MASKS_PER_LAYER):
mask = noise_mask(w, h, NOISE_SCALES[j])
mask_path = f"data/layer_{i}_mask_{j}.png"
mask.save(os.path.join(tmp, mask_path))
# Apply mask to alpha channel of base image
masked_image = base.copy()
r, g, b, a = masked_image.split()
# Multiply existing alpha by mask
new_alpha = ImageChops.multiply(a, mask)
masked_image.putalpha(new_alpha)
layer_path = f"data/layer_{i}_{j}.png"
masked_image.save(os.path.join(tmp, layer_path))
group_layers.append({
"name": f"mask {j}",
"src": mask_path
"name": f"layer {j}",
"src": layer_path
})
groups.append({