feat: imgage feature

This commit is contained in:
2026-04-01 12:31:23 +02:00
parent 175de893aa
commit 528d2d8519
11 changed files with 431 additions and 7 deletions

View File

@@ -117,6 +117,23 @@ def cmd_deploy(args: argparse.Namespace) -> int:
return 0
def cmd_image(args: argparse.Namespace) -> int:
"""Convert an image file to character art."""
from uframe.imaging import convert_image
try:
lines = convert_image(args.file, mode=args.mode, width=args.width,
dither=args.dither, invert=args.invert)
for line in lines:
print(line)
except ImportError:
print("Error: Pillow is required: pip install Pillow", file=sys.stderr)
return 1
except FileNotFoundError:
print(f"Error: Image not found: {args.file}", file=sys.stderr)
return 1
return 0
def main() -> int:
parser = argparse.ArgumentParser(
prog="uframe",
@@ -151,6 +168,14 @@ def main() -> int:
p_deploy.add_argument("--width", type=int, default=64, help="Page width")
p_deploy.add_argument("--theme", default="", help="Theme name")
# image (standalone conversion)
p_image = sub.add_parser("image", help="Convert image to character art")
p_image.add_argument("file", help="Path to image file")
p_image.add_argument("--mode", default="braille", help="braille, block, ascii, halfblock")
p_image.add_argument("--width", type=int, default=40, help="Output width")
p_image.add_argument("--dither", default="floyd", help="floyd, threshold, none")
p_image.add_argument("--invert", action="store_true", help="Invert light/dark")
args = parser.parse_args()
commands = {
@@ -158,6 +183,7 @@ def main() -> int:
"compile": cmd_compile,
"check": cmd_check,
"deploy": cmd_deploy,
"image": cmd_image,
}
return commands[args.command](args)