Add new PNG images for clean and preview outputs

- Added `image_clean.png` to the output directory for the clean image representation.
- Added `image_clean_preview.png` for the preview of the clean image.
- Introduced `image_svg_clean.png` for the SVG clean image representation.
This commit is contained in:
John Doe
2026-03-27 23:40:27 +01:00
parent e7c5ebb119
commit 02202e4d3d
403 changed files with 40415 additions and 411 deletions
+49
View File
@@ -0,0 +1,49 @@
#!/usr/bin/env python3
import argparse
import json
from pathlib import Path
from PIL import Image
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Convert an image file into a JSON matrix of RGBA pixels."
)
parser.add_argument("input_image", type=Path, help="Source image path")
parser.add_argument("output_json", type=Path, help="Destination JSON path")
return parser.parse_args()
def image_to_matrix(image_path: Path) -> dict:
with Image.open(image_path) as image:
rgba_image = image.convert("RGBA")
width, height = rgba_image.size
pixel_map = rgba_image.load()
rows = [
[list(pixel_map[x, y]) for x in range(width)]
for y in range(height)
]
return {
"source": image_path.name,
"width": width,
"height": height,
"mode": "RGBA",
"pixels": rows,
}
def main() -> None:
args = parse_args()
data = image_to_matrix(args.input_image)
args.output_json.parent.mkdir(parents=True, exist_ok=True)
args.output_json.write_text(json.dumps(data, indent=2), encoding="utf-8")
print(
f"Wrote {args.output_json} with {data['width']}x{data['height']} RGBA pixels"
)
if __name__ == "__main__":
main()
+53
View File
@@ -0,0 +1,53 @@
#!/usr/bin/env python3
import argparse
import json
from pathlib import Path
from PIL import Image
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Convert a JSON RGBA matrix back into a PNG image."
)
parser.add_argument("input_json", type=Path, help="Source JSON path")
parser.add_argument("output_png", type=Path, help="Destination PNG path")
return parser.parse_args()
def load_matrix(json_path: Path) -> tuple[int, int, list[tuple[int, int, int, int]]]:
data = json.loads(json_path.read_text(encoding="utf-8"))
width = int(data["width"])
height = int(data["height"])
rows = data["pixels"]
if len(rows) != height:
raise ValueError(f"Expected {height} rows, found {len(rows)}")
flat_pixels: list[tuple[int, int, int, int]] = []
for row_index, row in enumerate(rows):
if len(row) != width:
raise ValueError(
f"Expected row {row_index} to contain {width} pixels, found {len(row)}"
)
for pixel in row:
if len(pixel) != 4:
raise ValueError("Each pixel must contain 4 RGBA channels")
flat_pixels.append(tuple(int(channel) for channel in pixel))
return width, height, flat_pixels
def main() -> None:
args = parse_args()
width, height, pixels = load_matrix(args.input_json)
image = Image.new("RGBA", (width, height))
image.putdata(pixels)
args.output_png.parent.mkdir(parents=True, exist_ok=True)
image.save(args.output_png, format="PNG")
print(f"Wrote {args.output_png} with {width}x{height} RGBA pixels")
if __name__ == "__main__":
main()
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 421 B

File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 804 B

File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 815 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 885 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB