Files
huepaper/src/huepaper/generator.py
Profitroll e7a098bdf5
Some checks failed
Tests / test (3.8) (push) Waiting to run
Tests / test (3.9) (push) Waiting to run
Tests / test (3.10) (push) Successful in 1m26s
Tests / test (3.11) (push) Has been cancelled
RGB mode fixed
2024-01-21 17:28:57 +01:00

82 lines
2.1 KiB
Python

from pathlib import Path
from typing import Union
from PIL.Image import Image
from huepaper.utils import (
add_emblem,
add_lines,
add_pixelation,
create_base_image,
create_colors,
get_base_color,
save_image,
)
def generate(
width: int = 1920,
height: int = 1080,
color: Union[str, None] = None,
lines: Union[float, None] = None,
lines_bright: Union[float, None] = None,
lines_dark: Union[float, None] = None,
emblem: Union[str, Path, None] = None,
pixelate: Union[str, None] = None,
hue_max: float = 0.1,
sat_min: float = 0.2,
sat_max: float = 1.0,
lum_min: float = 0.2,
lum_max: float = 0.9,
_output: Union[str, Path, None] = None,
) -> Image:
# Get size
if width is None or height is None:
raise ValueError("The size must be provided")
# Check preconditions
if pixelate:
try:
values = pixelate.split("x")
px = int(values[0])
py = int(values[1])
except:
raise ValueError("Pixelation value must be set in form: 42x42")
try:
random_color = not color
base_color = get_base_color(color, sat_min, sat_max, lum_min, lum_max)
if random_color:
print(f"Selected random base color: {base_color.hex}")
c1, c2, c3, c4 = create_colors(
base_color, hue_max, sat_min, sat_max, lum_min, lum_max
)
image = create_base_image(c1, c2, c3, c4, width, height)
if lines:
image = add_lines(image, base_color.rgb + (lines,))
if lines_bright:
image = add_lines(image, (1.0, 1.0, 1.0, lines_bright))
if lines_dark:
image = add_lines(image, (0.0, 0.0, 0.0, lines_dark))
if pixelate:
image = add_pixelation(image, px, py)
if emblem:
image = add_emblem(image, emblem)
image = image.convert(mode="RGB")
if _output:
save_image(image, _output)
return
return image
except Exception as e:
print(e)
exit(1)