Image mode won't be attempted to be set
This commit is contained in:
parent
67b5be094c
commit
b67b23036d
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -10,5 +10,7 @@
|
||||
},
|
||||
"[toml]": {
|
||||
"editor.defaultFormatter": "tamasfe.even-better-toml"
|
||||
}
|
||||
},
|
||||
"python.analysis.typeCheckingMode": "basic",
|
||||
"python.analysis.autoImportCompletions": true
|
||||
}
|
@ -44,10 +44,10 @@ def generate(
|
||||
raise ValueError("Pixelation value must be set in form: 42x42")
|
||||
|
||||
try:
|
||||
random_color = False if color else True
|
||||
random_color = not color
|
||||
base_color = get_base_color(color, sat_min, sat_max, lum_min, lum_max)
|
||||
if random_color:
|
||||
print("Selected random base color: {}".format(base_color.hex))
|
||||
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
|
||||
@ -68,8 +68,6 @@ def generate(
|
||||
if emblem:
|
||||
image = add_emblem(image, emblem)
|
||||
|
||||
image.mode = "RGB"
|
||||
|
||||
if _output:
|
||||
save_image(image, _output)
|
||||
return
|
||||
@ -77,5 +75,5 @@ def generate(
|
||||
return image
|
||||
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
print(e)
|
||||
exit(1)
|
||||
|
@ -23,9 +23,9 @@ def get_base_color(
|
||||
base_color = Color(color_string)
|
||||
except:
|
||||
try:
|
||||
base_color = Color("#{}".format(color_string))
|
||||
base_color = Color(f"#{color_string}")
|
||||
except:
|
||||
raise Exception("Invalid color expression: {}".format(color_string))
|
||||
raise Exception(f"Invalid color expression: {color_string}")
|
||||
|
||||
return base_color
|
||||
|
||||
@ -43,7 +43,7 @@ def create_colors(
|
||||
max_lum_diff = 0.1
|
||||
|
||||
# Create four random colors similar to the given base_color
|
||||
for i in range(0, 4):
|
||||
for _ in range(4):
|
||||
tmp_hue = base_color.hue + random.uniform(-hue_max / 2.0, hue_max / 2.0)
|
||||
if tmp_hue > 1.0:
|
||||
tmp_hue -= 1
|
||||
@ -60,7 +60,7 @@ def create_colors(
|
||||
return tuple(colors)
|
||||
|
||||
|
||||
def create_base_image(c1, c2, c3, c4, width=1920, height=1080):
|
||||
def create_base_image(c1, c2, c3, c4, width=1920, height=1080) -> Image:
|
||||
"""Create a base huepaper by four corner colors.
|
||||
|
||||
c1 - top left
|
||||
@ -79,9 +79,8 @@ def create_base_image(c1, c2, c3, c4, width=1920, height=1080):
|
||||
)
|
||||
|
||||
im_arr = np.array([r, g, b]).T
|
||||
image = Image.fromarray(np.uint8(im_arr * 255)).convert("RGBA")
|
||||
|
||||
return image
|
||||
return Image.fromarray(np.uint8(im_arr * 255)).convert("RGBA")
|
||||
|
||||
|
||||
def add_lines(image, color):
|
||||
@ -103,7 +102,8 @@ def add_lines(image, color):
|
||||
)
|
||||
space = rand_width() // 2
|
||||
offset = random.randint(0, space)
|
||||
for i in range(0, number_of_lines):
|
||||
|
||||
for _ in range(number_of_lines):
|
||||
line_width = rand_width()
|
||||
x = offset + space + (line_width // 2)
|
||||
draw.line((x, 0, x, height), fill=color, width=line_width)
|
||||
@ -138,7 +138,7 @@ def add_emblem(image, filepath):
|
||||
try:
|
||||
emblem_image = Image.open(filepath)
|
||||
except Exception as e:
|
||||
raise Exception("Failed to load emblem: {}".format(e))
|
||||
raise Exception(f"Failed to load emblem: {e}")
|
||||
|
||||
# Exit if emblem is too big
|
||||
if emblem_image.size[0] > width or emblem_image.size[1] > height:
|
||||
@ -161,11 +161,10 @@ def save_image(image, filepath):
|
||||
# Check whether file exists
|
||||
if os.path.isfile(filepath):
|
||||
overwrite = input(
|
||||
"The file {} already exists. Do you want to overwrite it? [y/N] ".format(
|
||||
filepath
|
||||
f"The file {filepath} already exists. Do you want to overwrite it? [y/N] "
|
||||
)
|
||||
)
|
||||
if overwrite != "y" and overwrite != "Y":
|
||||
|
||||
if overwrite not in ["y", "Y"]:
|
||||
save = False
|
||||
|
||||
if save:
|
||||
@ -175,9 +174,10 @@ def save_image(image, filepath):
|
||||
image.save(filepath)
|
||||
stop = True
|
||||
except Exception as e:
|
||||
print("Failed to save wallpaper: {}".format(e))
|
||||
print(f"Failed to save wallpaper: {e}")
|
||||
again = input("Do you want to try again? [Y/n] ")
|
||||
if again == "n" or again == "N":
|
||||
|
||||
if again in ["n", "N"]:
|
||||
stop = True
|
||||
else:
|
||||
filepath = input(
|
||||
|
Loading…
Reference in New Issue
Block a user