Skip to content

Commit

Permalink
Resize image before for faster color generation
Browse files Browse the repository at this point in the history
  • Loading branch information
midn8hustlr committed Mar 26, 2024
1 parent 5027045 commit c62d771
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions .config/ags/scripts/color_generation/generate_colors_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

parser = argparse.ArgumentParser(description='Color generation script')
parser.add_argument('--path', type=str, default=None, help='generate colorscheme from image')
parser.add_argument('--quality', type=int , default=1 , help='pixels to skip in image, setting 1 means skip no pixels')
parser.add_argument('--basewidth', type=int , default=128 , help='resize the image to the specified width for faster color generation')
parser.add_argument('--color', type=str, default=None, help='generate colorscheme from color')
parser.add_argument('--mode', type=str, choices=['dark', 'light'], default='dark', help='dark or light mode')
parser.add_argument('--scheme', type=str, default=None, help='material scheme to use')
Expand All @@ -29,15 +29,14 @@

if args.path is not None:
image = Image.open(args.path)
pixel_len = image.width * image.height
image_data = image.getdata()
pixel_array = [image_data[_] for _ in range(0, pixel_len, args.quality)]
colors = QuantizeCelebi(pixel_array, 128)
wpercent = (args.basewidth/float(image.size[0]))
hsize = int((float(image.size[1])*float(wpercent)))
image = image.resize((args.basewidth, hsize), Image.Resampling.BICUBIC)
colors = QuantizeCelebi(image.getdata(), 128)
argb = Score.score(colors)[0]

if args.cache is not None:
export_color_file=args.cache
with open(export_color_file, 'w') as file:
with open(args.cache, 'w') as file:
file.write(argb_to_hex(argb))
hct = Hct.from_int(argb)
if(args.smart):
Expand Down Expand Up @@ -85,7 +84,6 @@
print('Hue:', hct.hue)
print('Chroma:', hct.chroma)
print('Tone:', hct.tone)
print(argb)
r, g, b, a = rgba_from_argb(argb)
hex_code = argb_to_hex(argb)
print('Selected Color:', "\x1B[38;2;{};{};{}m{}\x1B[0m".format(r, g, b, "\x1b[7m \x1b[7m"), hex_code)
Expand Down

0 comments on commit c62d771

Please sign in to comment.