Change size arguments
This commit is contained in:
parent
8cd66e3b43
commit
b26fae647f
184
huepaper.org
184
huepaper.org
@ -26,7 +26,7 @@ The logo of huepaper is printed on startup.
|
|||||||
|
|
||||||
#+BEGIN_SRC python
|
#+BEGIN_SRC python
|
||||||
def print_logo():
|
def print_logo():
|
||||||
logo = '''
|
logo = """
|
||||||
.lk.
|
.lk.
|
||||||
cO.
|
cO.
|
||||||
cO.;:lc. ,c. .cc .,',c; .,c.;coc. ;,.,c. ':l.:lo: '',:c. '::.lo.
|
cO.;:lc. ,c. .cc .,',c; .,c.;coc. ;,.,c. ':l.:lo: '',:c. '::.lo.
|
||||||
@ -37,13 +37,12 @@ The logo of huepaper is printed on startup.
|
|||||||
:O. kk
|
:O. kk
|
||||||
lO, OO
|
lO, OO
|
||||||
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO00O0000000000000000;
|
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO00O0000000000000000;
|
||||||
''';
|
"""
|
||||||
print(logo)
|
print(logo)
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
** Base color
|
** Base color
|
||||||
|
|
||||||
|
|
||||||
Every huepaper has a base color.
|
Every huepaper has a base color.
|
||||||
It is used to calculate the final colors.
|
It is used to calculate the final colors.
|
||||||
|
|
||||||
@ -59,14 +58,14 @@ If no color is given, a random one is chosen.
|
|||||||
sat = random.uniform(sat_min, sat_max)
|
sat = random.uniform(sat_min, sat_max)
|
||||||
lum = random.uniform(lum_min, lum_max)
|
lum = random.uniform(lum_min, lum_max)
|
||||||
base_color = Color(hue=hue, saturation=sat, luminance=lum)
|
base_color = Color(hue=hue, saturation=sat, luminance=lum)
|
||||||
print('Selected random base color: {}'.format(base_color.hex))
|
print("Selected random base color: {}".format(base_color.hex))
|
||||||
|
|
||||||
# Else try to parse string
|
# Else try to parse string
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
base_color = Color(color_string)
|
base_color = Color(color_string)
|
||||||
except:
|
except:
|
||||||
print('Not a valid color expression: {}'.format(color_string))
|
print("Not a valid color expression: {}".format(color_string))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
return base_color
|
return base_color
|
||||||
@ -119,7 +118,11 @@ All other pixel colors are linear interpolated.
|
|||||||
def create_base_image(c1, c2, c3, c4):
|
def create_base_image(c1, c2, c3, c4):
|
||||||
|
|
||||||
# Lambda for adding four colors
|
# Lambda for adding four colors
|
||||||
add = lambda c1, c2, c3, c4 : (c1[0] + c2[0] + c3[0] + c4[0], c1[1] + c2[1] + c3[1] + c4[1], c1[2] + c2[2] + c3[2] + c4[2])
|
add = lambda c1, c2, c3, c4: (
|
||||||
|
c1[0] + c2[0] + c3[0] + c4[0],
|
||||||
|
c1[1] + c2[1] + c3[1] + c4[1],
|
||||||
|
c1[2] + c2[2] + c3[2] + c4[2],
|
||||||
|
)
|
||||||
|
|
||||||
# Lambda for multiplying a color with a factor
|
# Lambda for multiplying a color with a factor
|
||||||
mul = lambda c, x: (c[0] * x, c[1] * x, c[2] * x)
|
mul = lambda c, x: (c[0] * x, c[1] * x, c[2] * x)
|
||||||
@ -129,10 +132,17 @@ All other pixel colors are linear interpolated.
|
|||||||
|
|
||||||
# Lambda for calculating a color at x and y in range [0, 1]
|
# Lambda for calculating a color at x and y in range [0, 1]
|
||||||
# Color limits are set at creation
|
# Color limits are set at creation
|
||||||
col = lambda x, y, c1 = c1, c2 = c2, c3 = c3, c4 = c4 : cor(add(mul(c1, (1.0 - x) * (1.0 - y)), mul(c2, x * (1.0 - y)), mul(c3, x * y), mul(c4, (1.0 - x) * y)))
|
col = lambda x, y, c1=c1, c2=c2, c3=c3, c4=c4: cor(
|
||||||
|
add(
|
||||||
|
mul(c1, (1.0 - x) * (1.0 - y)),
|
||||||
|
mul(c2, x * (1.0 - y)),
|
||||||
|
mul(c3, x * y),
|
||||||
|
mul(c4, (1.0 - x) * y),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# Create image
|
# Create image
|
||||||
image = Image.new('RGBA', (width, height))
|
image = Image.new("RGBA", (width, height))
|
||||||
pixels = image.load()
|
pixels = image.load()
|
||||||
|
|
||||||
for x in range(0, width):
|
for x in range(0, width):
|
||||||
@ -149,7 +159,7 @@ Vertical lines can be added on the side of the huepaper.
|
|||||||
#+BEGIN_SRC python
|
#+BEGIN_SRC python
|
||||||
def add_lines(image, color):
|
def add_lines(image, color):
|
||||||
|
|
||||||
line_image = Image.new('RGBA', (width, height), (0, 0, 0, 0))
|
line_image = Image.new("RGBA", (width, height), (0, 0, 0, 0))
|
||||||
draw = ImageDraw.Draw(line_image)
|
draw = ImageDraw.Draw(line_image)
|
||||||
|
|
||||||
# Set color
|
# Set color
|
||||||
@ -159,7 +169,9 @@ Vertical lines can be added on the side of the huepaper.
|
|||||||
number_of_lines = random.randint(1, 3)
|
number_of_lines = random.randint(1, 3)
|
||||||
scale = width / 100.0
|
scale = width / 100.0
|
||||||
base_width = random.randint(int(2 * scale), int(5 * scale))
|
base_width = random.randint(int(2 * scale), int(5 * scale))
|
||||||
rand_width = lambda base_width = base_width : base_width + random.randint(-base_width // 2, base_width // 2)
|
rand_width = lambda base_width=base_width: base_width + random.randint(
|
||||||
|
-base_width // 2, base_width // 2
|
||||||
|
)
|
||||||
space = rand_width() // 2
|
space = rand_width() // 2
|
||||||
offset = random.randint(0, space)
|
offset = random.randint(0, space)
|
||||||
for i in range(0, number_of_lines):
|
for i in range(0, number_of_lines):
|
||||||
@ -205,16 +217,19 @@ This is loaded from a file and placed in the center.
|
|||||||
try:
|
try:
|
||||||
emblem_image = Image.open(filepath)
|
emblem_image = Image.open(filepath)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Failed to load emblem: {}'.format(e))
|
print("Failed to load emblem: {}".format(e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Exit if emblem is too big
|
# Exit if emblem is too big
|
||||||
if emblem_image.size[0] > width or emblem_image.size[1] > height:
|
if emblem_image.size[0] > width or emblem_image.size[1] > height:
|
||||||
print('Emblem can\'t be bigger than the wallpaper')
|
print("Emblem can't be bigger than the wallpaper")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Insert emblem in the center
|
# Insert emblem in the center
|
||||||
offset = ((image.size[0] - emblem_image.size[0]) // 2, (image.size[1] - emblem_image.size[1]) // 2)
|
offset = (
|
||||||
|
(image.size[0] - emblem_image.size[0]) // 2,
|
||||||
|
(image.size[1] - emblem_image.size[1]) // 2,
|
||||||
|
)
|
||||||
image.alpha_composite(emblem_image, offset)
|
image.alpha_composite(emblem_image, offset)
|
||||||
|
|
||||||
return image
|
return image
|
||||||
@ -232,8 +247,12 @@ Already existing files are only overwritten if the user wants to.
|
|||||||
|
|
||||||
# Check whether file exists
|
# Check whether file exists
|
||||||
if os.path.isfile(filepath):
|
if os.path.isfile(filepath):
|
||||||
overwrite = input('The file {} already exists. Do you want to overwrite it? [y/N] '.format(filepath))
|
overwrite = input(
|
||||||
if overwrite != 'y' and overwrite != 'Y':
|
"The file {} already exists. Do you want to overwrite it? [y/N] ".format(
|
||||||
|
filepath
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if overwrite != "y" and overwrite != "Y":
|
||||||
save = False
|
save = False
|
||||||
|
|
||||||
if save:
|
if save:
|
||||||
@ -244,12 +263,14 @@ Already existing files are only overwritten if the user wants to.
|
|||||||
image.save(filepath)
|
image.save(filepath)
|
||||||
stop = True
|
stop = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Failed to save wallpaper: {}'.format(e))
|
print("Failed to save wallpaper: {}".format(e))
|
||||||
again = input('Do you want to try again? [Y/n] ')
|
again = input("Do you want to try again? [Y/n] ")
|
||||||
if again == 'n' or again == 'N':
|
if again == "n" or again == "N":
|
||||||
stop = True
|
stop = True
|
||||||
else:
|
else:
|
||||||
filepath = input('Please enter new path where the wallpaper shall be saved: ')
|
filepath = input(
|
||||||
|
"Please enter new path where the wallpaper shall be saved: "
|
||||||
|
)
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
** Main
|
** Main
|
||||||
@ -261,27 +282,92 @@ In the main routine, the arguments are parsed and the image is created.
|
|||||||
|
|
||||||
global width, height, max_hue, sat_min, sat_max, lum_min, lum_max
|
global width, height, max_hue, sat_min, sat_max, lum_min, lum_max
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description = 'Create wallpapers based on color hues.')
|
parser = argparse.ArgumentParser(
|
||||||
parser.add_argument('-W', '--width', default = 1920, type = int, help = 'width of huepaper (default: 1920)')
|
description="Create wallpapers based on color hues."
|
||||||
parser.add_argument('-H', '--height', default = 1080, type = int, help = 'height of huepaper (default: 1080)')
|
)
|
||||||
parser.add_argument('-c', '--color', help = 'color, the huepaper is generated from (uses a random color if not given)')
|
parser.add_argument(
|
||||||
parser.add_argument('-p', '--preview', action = 'store_true', help = 'preview huepaper')
|
"-s",
|
||||||
parser.add_argument('-o', '--output', help = 'file where to save the huepaper to (default: None)')
|
"--size",
|
||||||
parser.add_argument('-l', '--lines', nargs = '?', const = 0.3, type = float, help = 'include one to three random lines in base color with given opacity in range [0, 1] (default: 0.3)')
|
default="1920x1080",
|
||||||
parser.add_argument('-lb', '--lines_bright', nargs = '?', const = 0.1, type = float, help = 'include one to three bright random lines with given opacity in range [0, 1] (default: 0.1)')
|
help="size of huepaper in the form WIDTHxHEIGHT (default: 1920x1080)",
|
||||||
parser.add_argument('-ld', '--lines_dark', nargs = '?', const = 0.1, type = float, help = 'include one to three dark random lines with given opacity in range [0, 1] (default: 0.1)')
|
)
|
||||||
parser.add_argument('-P', '--pixelate', help = "pixelate image (e.g. 42x42)")
|
parser.add_argument(
|
||||||
parser.add_argument('-e', '--emblem', help = 'emblem to add in the center of the huepaper')
|
"-c",
|
||||||
parser.add_argument('-hue', default = 0.1, type = float, help = 'maximum hue to differ from given color in range [0, 1] (default: 0.1)')
|
"--color",
|
||||||
parser.add_argument('-smin', default = 0.2, type = float, help = 'minimum satisfaction for colors in range [0, 1] (default: 0.2)')
|
help="color, the huepaper is generated from (uses a random color if not given)",
|
||||||
parser.add_argument('-smax', default = 1.0, type = float, help = 'maximum satisfaction for colors in range [0, 1] (default: 1.0)')
|
)
|
||||||
parser.add_argument('-lmin', default = 0.2, type = float, help = 'minimum luminance for colors in range [0, 1] (default: 0.2)')
|
parser.add_argument("-p", "--preview", action="store_true", help="preview huepaper")
|
||||||
parser.add_argument('-lmax', default = 0.9, type = float, help = 'maximum luminance for colors in range [0, 1] (default: 0.9)')
|
parser.add_argument(
|
||||||
|
"-o", "--output", help="file where to save the huepaper to (default: None)"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-l",
|
||||||
|
"--lines",
|
||||||
|
nargs="?",
|
||||||
|
const=0.3,
|
||||||
|
type=float,
|
||||||
|
help="include one to three random lines in base color with given opacity in range [0, 1] (default: 0.3)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-lb",
|
||||||
|
"--lines_bright",
|
||||||
|
nargs="?",
|
||||||
|
const=0.1,
|
||||||
|
type=float,
|
||||||
|
help="include one to three bright random lines with given opacity in range [0, 1] (default: 0.1)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-ld",
|
||||||
|
"--lines_dark",
|
||||||
|
nargs="?",
|
||||||
|
const=0.1,
|
||||||
|
type=float,
|
||||||
|
help="include one to three dark random lines with given opacity in range [0, 1] (default: 0.1)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-P",
|
||||||
|
"--pixelate",
|
||||||
|
nargs="?",
|
||||||
|
const="16x9",
|
||||||
|
help="pixelate image with WIDTHxHEIGHT (default: 16x9)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-e", "--emblem", help="emblem to add in the center of the huepaper"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-hue",
|
||||||
|
default=0.1,
|
||||||
|
type=float,
|
||||||
|
help="maximum hue to differ from given color in range [0, 1] (default: 0.1)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-smin",
|
||||||
|
default=0.2,
|
||||||
|
type=float,
|
||||||
|
help="minimum satisfaction for colors in range [0, 1] (default: 0.2)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-smax",
|
||||||
|
default=1.0,
|
||||||
|
type=float,
|
||||||
|
help="maximum satisfaction for colors in range [0, 1] (default: 1.0)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-lmin",
|
||||||
|
default=0.2,
|
||||||
|
type=float,
|
||||||
|
help="minimum luminance for colors in range [0, 1] (default: 0.2)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-lmax",
|
||||||
|
default=0.9,
|
||||||
|
type=float,
|
||||||
|
help="maximum luminance for colors in range [0, 1] (default: 0.9)",
|
||||||
|
)
|
||||||
|
|
||||||
# Get args
|
# Get args
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
width = args.width
|
size = args.size
|
||||||
height = args.height
|
|
||||||
color = args.color
|
color = args.color
|
||||||
preview = args.preview
|
preview = args.preview
|
||||||
output = args.output
|
output = args.output
|
||||||
@ -296,16 +382,24 @@ In the main routine, the arguments are parsed and the image is created.
|
|||||||
lum_min = args.lmin
|
lum_min = args.lmin
|
||||||
lum_max = args.lmax
|
lum_max = args.lmax
|
||||||
|
|
||||||
|
# Get size
|
||||||
|
try:
|
||||||
|
values = size.split("x")
|
||||||
|
width = int(values[0])
|
||||||
|
height = int(values[1])
|
||||||
|
except:
|
||||||
|
parser.error("The size must be given in form: 1920x1080")
|
||||||
|
|
||||||
# Check preconditions
|
# Check preconditions
|
||||||
if not preview and not output:
|
if not preview and not output:
|
||||||
parser.error('You must either set -p (--preview) or -o (--output)')
|
parser.error("You must either set -p (--preview) or -o (--output)")
|
||||||
if pixelate:
|
if pixelate:
|
||||||
try:
|
try:
|
||||||
values = pixelate.split('x')
|
values = pixelate.split("x")
|
||||||
px = int(values[0])
|
px = int(values[0])
|
||||||
py = int(values[1])
|
py = int(values[1])
|
||||||
except:
|
except:
|
||||||
parser.error('Pixelation value must be set in form: 42x42')
|
parser.error("Pixelation value must be set in form: 42x42")
|
||||||
|
|
||||||
print_logo()
|
print_logo()
|
||||||
base_color = get_base_color(color)
|
base_color = get_base_color(color)
|
||||||
@ -325,20 +419,20 @@ In the main routine, the arguments are parsed and the image is created.
|
|||||||
if emblem:
|
if emblem:
|
||||||
image = add_emblem(image, emblem)
|
image = add_emblem(image, emblem)
|
||||||
|
|
||||||
image.mode = 'RGB'
|
image.mode = "RGB"
|
||||||
|
|
||||||
if preview:
|
if preview:
|
||||||
image.show()
|
image.show()
|
||||||
if not output:
|
if not output:
|
||||||
save = input('Do you want to save the image? [y/N] ')
|
save = input("Do you want to save the image? [y/N] ")
|
||||||
if save == 'y' or save == 'Y':
|
if save == "y" or save == "Y":
|
||||||
path = input('Enter the path where the wallpaper shall be saved: ')
|
path = input("Enter the path where the wallpaper shall be saved: ")
|
||||||
save_image(path, image)
|
save_image(path, image)
|
||||||
|
|
||||||
if output:
|
if output:
|
||||||
save_image(output, image)
|
save_image(output, image)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
183
huepaper.py
183
huepaper.py
@ -7,7 +7,7 @@ from colour import Color
|
|||||||
from PIL import Image, ImageDraw, ImageOps
|
from PIL import Image, ImageDraw, ImageOps
|
||||||
|
|
||||||
def print_logo():
|
def print_logo():
|
||||||
logo = '''
|
logo = """
|
||||||
.lk.
|
.lk.
|
||||||
cO.
|
cO.
|
||||||
cO.;:lc. ,c. .cc .,',c; .,c.;coc. ;,.,c. ':l.:lo: '',:c. '::.lo.
|
cO.;:lc. ,c. .cc .,',c; .,c.;coc. ;,.,c. ':l.:lo: '',:c. '::.lo.
|
||||||
@ -18,7 +18,7 @@ def print_logo():
|
|||||||
:O. kk
|
:O. kk
|
||||||
lO, OO
|
lO, OO
|
||||||
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO00O0000000000000000;
|
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO00O0000000000000000;
|
||||||
''';
|
"""
|
||||||
print(logo)
|
print(logo)
|
||||||
|
|
||||||
def get_base_color(color_string=None):
|
def get_base_color(color_string=None):
|
||||||
@ -29,14 +29,14 @@ def get_base_color(color_string = None):
|
|||||||
sat = random.uniform(sat_min, sat_max)
|
sat = random.uniform(sat_min, sat_max)
|
||||||
lum = random.uniform(lum_min, lum_max)
|
lum = random.uniform(lum_min, lum_max)
|
||||||
base_color = Color(hue=hue, saturation=sat, luminance=lum)
|
base_color = Color(hue=hue, saturation=sat, luminance=lum)
|
||||||
print('Selected random base color: {}'.format(base_color.hex))
|
print("Selected random base color: {}".format(base_color.hex))
|
||||||
|
|
||||||
# Else try to parse string
|
# Else try to parse string
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
base_color = Color(color_string)
|
base_color = Color(color_string)
|
||||||
except:
|
except:
|
||||||
print('Not a valid color expression: {}'.format(color_string))
|
print("Not a valid color expression: {}".format(color_string))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
return base_color
|
return base_color
|
||||||
@ -73,7 +73,11 @@ def create_colors(base_color):
|
|||||||
def create_base_image(c1, c2, c3, c4):
|
def create_base_image(c1, c2, c3, c4):
|
||||||
|
|
||||||
# Lambda for adding four colors
|
# Lambda for adding four colors
|
||||||
add = lambda c1, c2, c3, c4 : (c1[0] + c2[0] + c3[0] + c4[0], c1[1] + c2[1] + c3[1] + c4[1], c1[2] + c2[2] + c3[2] + c4[2])
|
add = lambda c1, c2, c3, c4: (
|
||||||
|
c1[0] + c2[0] + c3[0] + c4[0],
|
||||||
|
c1[1] + c2[1] + c3[1] + c4[1],
|
||||||
|
c1[2] + c2[2] + c3[2] + c4[2],
|
||||||
|
)
|
||||||
|
|
||||||
# Lambda for multiplying a color with a factor
|
# Lambda for multiplying a color with a factor
|
||||||
mul = lambda c, x: (c[0] * x, c[1] * x, c[2] * x)
|
mul = lambda c, x: (c[0] * x, c[1] * x, c[2] * x)
|
||||||
@ -83,10 +87,17 @@ def create_base_image(c1, c2, c3, c4):
|
|||||||
|
|
||||||
# Lambda for calculating a color at x and y in range [0, 1]
|
# Lambda for calculating a color at x and y in range [0, 1]
|
||||||
# Color limits are set at creation
|
# Color limits are set at creation
|
||||||
col = lambda x, y, c1 = c1, c2 = c2, c3 = c3, c4 = c4 : cor(add(mul(c1, (1.0 - x) * (1.0 - y)), mul(c2, x * (1.0 - y)), mul(c3, x * y), mul(c4, (1.0 - x) * y)))
|
col = lambda x, y, c1=c1, c2=c2, c3=c3, c4=c4: cor(
|
||||||
|
add(
|
||||||
|
mul(c1, (1.0 - x) * (1.0 - y)),
|
||||||
|
mul(c2, x * (1.0 - y)),
|
||||||
|
mul(c3, x * y),
|
||||||
|
mul(c4, (1.0 - x) * y),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# Create image
|
# Create image
|
||||||
image = Image.new('RGBA', (width, height))
|
image = Image.new("RGBA", (width, height))
|
||||||
pixels = image.load()
|
pixels = image.load()
|
||||||
|
|
||||||
for x in range(0, width):
|
for x in range(0, width):
|
||||||
@ -97,7 +108,7 @@ def create_base_image(c1, c2, c3, c4):
|
|||||||
|
|
||||||
def add_lines(image, color):
|
def add_lines(image, color):
|
||||||
|
|
||||||
line_image = Image.new('RGBA', (width, height), (0, 0, 0, 0))
|
line_image = Image.new("RGBA", (width, height), (0, 0, 0, 0))
|
||||||
draw = ImageDraw.Draw(line_image)
|
draw = ImageDraw.Draw(line_image)
|
||||||
|
|
||||||
# Set color
|
# Set color
|
||||||
@ -107,7 +118,9 @@ def add_lines(image, color):
|
|||||||
number_of_lines = random.randint(1, 3)
|
number_of_lines = random.randint(1, 3)
|
||||||
scale = width / 100.0
|
scale = width / 100.0
|
||||||
base_width = random.randint(int(2 * scale), int(5 * scale))
|
base_width = random.randint(int(2 * scale), int(5 * scale))
|
||||||
rand_width = lambda base_width = base_width : base_width + random.randint(-base_width // 2, base_width // 2)
|
rand_width = lambda base_width=base_width: base_width + random.randint(
|
||||||
|
-base_width // 2, base_width // 2
|
||||||
|
)
|
||||||
space = rand_width() // 2
|
space = rand_width() // 2
|
||||||
offset = random.randint(0, space)
|
offset = random.randint(0, space)
|
||||||
for i in range(0, number_of_lines):
|
for i in range(0, number_of_lines):
|
||||||
@ -139,16 +152,19 @@ def add_emblem(image, filepath):
|
|||||||
try:
|
try:
|
||||||
emblem_image = Image.open(filepath)
|
emblem_image = Image.open(filepath)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Failed to load emblem: {}'.format(e))
|
print("Failed to load emblem: {}".format(e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Exit if emblem is too big
|
# Exit if emblem is too big
|
||||||
if emblem_image.size[0] > width or emblem_image.size[1] > height:
|
if emblem_image.size[0] > width or emblem_image.size[1] > height:
|
||||||
print('Emblem can\'t be bigger than the wallpaper')
|
print("Emblem can't be bigger than the wallpaper")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Insert emblem in the center
|
# Insert emblem in the center
|
||||||
offset = ((image.size[0] - emblem_image.size[0]) // 2, (image.size[1] - emblem_image.size[1]) // 2)
|
offset = (
|
||||||
|
(image.size[0] - emblem_image.size[0]) // 2,
|
||||||
|
(image.size[1] - emblem_image.size[1]) // 2,
|
||||||
|
)
|
||||||
image.alpha_composite(emblem_image, offset)
|
image.alpha_composite(emblem_image, offset)
|
||||||
|
|
||||||
return image
|
return image
|
||||||
@ -159,8 +175,12 @@ def save_image(filepath, image):
|
|||||||
|
|
||||||
# Check whether file exists
|
# Check whether file exists
|
||||||
if os.path.isfile(filepath):
|
if os.path.isfile(filepath):
|
||||||
overwrite = input('The file {} already exists. Do you want to overwrite it? [y/N] '.format(filepath))
|
overwrite = input(
|
||||||
if overwrite != 'y' and overwrite != 'Y':
|
"The file {} already exists. Do you want to overwrite it? [y/N] ".format(
|
||||||
|
filepath
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if overwrite != "y" and overwrite != "Y":
|
||||||
save = False
|
save = False
|
||||||
|
|
||||||
if save:
|
if save:
|
||||||
@ -171,38 +191,105 @@ def save_image(filepath, image):
|
|||||||
image.save(filepath)
|
image.save(filepath)
|
||||||
stop = True
|
stop = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Failed to save wallpaper: {}'.format(e))
|
print("Failed to save wallpaper: {}".format(e))
|
||||||
again = input('Do you want to try again? [Y/n] ')
|
again = input("Do you want to try again? [Y/n] ")
|
||||||
if again == 'n' or again == 'N':
|
if again == "n" or again == "N":
|
||||||
stop = True
|
stop = True
|
||||||
else:
|
else:
|
||||||
filepath = input('Please enter new path where the wallpaper shall be saved: ')
|
filepath = input(
|
||||||
|
"Please enter new path where the wallpaper shall be saved: "
|
||||||
|
)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
global width, height, max_hue, sat_min, sat_max, lum_min, lum_max
|
global width, height, max_hue, sat_min, sat_max, lum_min, lum_max
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description = 'Create wallpapers based on color hues.')
|
parser = argparse.ArgumentParser(
|
||||||
parser.add_argument('-W', '--width', default = 1920, type = int, help = 'width of huepaper (default: 1920)')
|
description="Create wallpapers based on color hues."
|
||||||
parser.add_argument('-H', '--height', default = 1080, type = int, help = 'height of huepaper (default: 1080)')
|
)
|
||||||
parser.add_argument('-c', '--color', help = 'color, the huepaper is generated from (uses a random color if not given)')
|
parser.add_argument(
|
||||||
parser.add_argument('-p', '--preview', action = 'store_true', help = 'preview huepaper')
|
"-s",
|
||||||
parser.add_argument('-o', '--output', help = 'file where to save the huepaper to (default: None)')
|
"--size",
|
||||||
parser.add_argument('-l', '--lines', nargs = '?', const = 0.3, type = float, help = 'include one to three random lines in base color with given opacity in range [0, 1] (default: 0.3)')
|
default="1920x1080",
|
||||||
parser.add_argument('-lb', '--lines_bright', nargs = '?', const = 0.1, type = float, help = 'include one to three bright random lines with given opacity in range [0, 1] (default: 0.1)')
|
help="size of huepaper in the form WIDTHxHEIGHT (default: 1920x1080)",
|
||||||
parser.add_argument('-ld', '--lines_dark', nargs = '?', const = 0.1, type = float, help = 'include one to three dark random lines with given opacity in range [0, 1] (default: 0.1)')
|
)
|
||||||
parser.add_argument('-P', '--pixelate', help = "pixelate image (e.g. 42x42)")
|
parser.add_argument(
|
||||||
parser.add_argument('-e', '--emblem', help = 'emblem to add in the center of the huepaper')
|
"-c",
|
||||||
parser.add_argument('-hue', default = 0.1, type = float, help = 'maximum hue to differ from given color in range [0, 1] (default: 0.1)')
|
"--color",
|
||||||
parser.add_argument('-smin', default = 0.2, type = float, help = 'minimum satisfaction for colors in range [0, 1] (default: 0.2)')
|
help="color, the huepaper is generated from (uses a random color if not given)",
|
||||||
parser.add_argument('-smax', default = 1.0, type = float, help = 'maximum satisfaction for colors in range [0, 1] (default: 1.0)')
|
)
|
||||||
parser.add_argument('-lmin', default = 0.2, type = float, help = 'minimum luminance for colors in range [0, 1] (default: 0.2)')
|
parser.add_argument("-p", "--preview", action="store_true", help="preview huepaper")
|
||||||
parser.add_argument('-lmax', default = 0.9, type = float, help = 'maximum luminance for colors in range [0, 1] (default: 0.9)')
|
parser.add_argument(
|
||||||
|
"-o", "--output", help="file where to save the huepaper to (default: None)"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-l",
|
||||||
|
"--lines",
|
||||||
|
nargs="?",
|
||||||
|
const=0.3,
|
||||||
|
type=float,
|
||||||
|
help="include one to three random lines in base color with given opacity in range [0, 1] (default: 0.3)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-lb",
|
||||||
|
"--lines_bright",
|
||||||
|
nargs="?",
|
||||||
|
const=0.1,
|
||||||
|
type=float,
|
||||||
|
help="include one to three bright random lines with given opacity in range [0, 1] (default: 0.1)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-ld",
|
||||||
|
"--lines_dark",
|
||||||
|
nargs="?",
|
||||||
|
const=0.1,
|
||||||
|
type=float,
|
||||||
|
help="include one to three dark random lines with given opacity in range [0, 1] (default: 0.1)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-P",
|
||||||
|
"--pixelate",
|
||||||
|
nargs="?",
|
||||||
|
const="16x9",
|
||||||
|
help="pixelate image with WIDTHxHEIGHT (default: 16x9)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-e", "--emblem", help="emblem to add in the center of the huepaper"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-hue",
|
||||||
|
default=0.1,
|
||||||
|
type=float,
|
||||||
|
help="maximum hue to differ from given color in range [0, 1] (default: 0.1)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-smin",
|
||||||
|
default=0.2,
|
||||||
|
type=float,
|
||||||
|
help="minimum satisfaction for colors in range [0, 1] (default: 0.2)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-smax",
|
||||||
|
default=1.0,
|
||||||
|
type=float,
|
||||||
|
help="maximum satisfaction for colors in range [0, 1] (default: 1.0)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-lmin",
|
||||||
|
default=0.2,
|
||||||
|
type=float,
|
||||||
|
help="minimum luminance for colors in range [0, 1] (default: 0.2)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-lmax",
|
||||||
|
default=0.9,
|
||||||
|
type=float,
|
||||||
|
help="maximum luminance for colors in range [0, 1] (default: 0.9)",
|
||||||
|
)
|
||||||
|
|
||||||
# Get args
|
# Get args
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
width = args.width
|
size = args.size
|
||||||
height = args.height
|
|
||||||
color = args.color
|
color = args.color
|
||||||
preview = args.preview
|
preview = args.preview
|
||||||
output = args.output
|
output = args.output
|
||||||
@ -217,16 +304,24 @@ def main():
|
|||||||
lum_min = args.lmin
|
lum_min = args.lmin
|
||||||
lum_max = args.lmax
|
lum_max = args.lmax
|
||||||
|
|
||||||
|
# Get size
|
||||||
|
try:
|
||||||
|
values = size.split("x")
|
||||||
|
width = int(values[0])
|
||||||
|
height = int(values[1])
|
||||||
|
except:
|
||||||
|
parser.error("The size must be given in form: 1920x1080")
|
||||||
|
|
||||||
# Check preconditions
|
# Check preconditions
|
||||||
if not preview and not output:
|
if not preview and not output:
|
||||||
parser.error('You must either set -p (--preview) or -o (--output)')
|
parser.error("You must either set -p (--preview) or -o (--output)")
|
||||||
if pixelate:
|
if pixelate:
|
||||||
try:
|
try:
|
||||||
values = pixelate.split('x')
|
values = pixelate.split("x")
|
||||||
px = int(values[0])
|
px = int(values[0])
|
||||||
py = int(values[1])
|
py = int(values[1])
|
||||||
except:
|
except:
|
||||||
parser.error('Pixelation value must be set in form: 42x42')
|
parser.error("Pixelation value must be set in form: 42x42")
|
||||||
|
|
||||||
print_logo()
|
print_logo()
|
||||||
base_color = get_base_color(color)
|
base_color = get_base_color(color)
|
||||||
@ -246,19 +341,19 @@ def main():
|
|||||||
if emblem:
|
if emblem:
|
||||||
image = add_emblem(image, emblem)
|
image = add_emblem(image, emblem)
|
||||||
|
|
||||||
image.mode = 'RGB'
|
image.mode = "RGB"
|
||||||
|
|
||||||
if preview:
|
if preview:
|
||||||
image.show()
|
image.show()
|
||||||
if not output:
|
if not output:
|
||||||
save = input('Do you want to save the image? [y/N] ')
|
save = input("Do you want to save the image? [y/N] ")
|
||||||
if save == 'y' or save == 'Y':
|
if save == "y" or save == "Y":
|
||||||
path = input('Enter the path where the wallpaper shall be saved: ')
|
path = input("Enter the path where the wallpaper shall be saved: ")
|
||||||
save_image(path, image)
|
save_image(path, image)
|
||||||
|
|
||||||
if output:
|
if output:
|
||||||
save_image(output, image)
|
save_image(output, image)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user