def main(): signal.signal(signal.SIGINT, signal_handler) console = Console() global gruvbox_factory gruvbox_factory = GoNord() gruvbox_factory.reset_palette() add_gruvbox_palette() console.print( Panel('🏭 [bold green] Gruvbox Factory [/] 🏭', expand=False, border_style='yellow')) console.print( '⚠️ WARNING ⚠️\n[italic]make sure you\'re in the same directory of the image you want to convert [/]\n' ) image_file = console.input( '🖼️ [bold yellow]Which image do you want to manufacture?[/] ') try: image = gruvbox_factory.open_image(image_file) except: console.print( '❌ [red]We had a problem in the pipeline! Make sure you\'re in the same path of the image you want to convert! [/]' ) sys.exit(0) console.print('🔨 [yellow]manufacturing your gruvbox wallpaper...[/]') gruvbox_factory.convert_image(image, save_path=('gruvbox_' + image_file)) console.print('✅ [bold green]Done![/] [green](saved as gruvbox_' + image_file + ')[/]')
def main(): signal.signal(signal.SIGINT, signal_handler) console = Console() gruvbox_factory = GoNord() gruvbox_factory.reset_palette() add_gruvbox_palette(gruvbox_factory) # Checks if there's an argument if len(sys.argv) > 1: image_paths = fromCommandArgument(console) else: image_paths = fromTui(console) for image_path in image_paths: if os.path.isfile(image_path): process_image(image_path, console, gruvbox_factory) else: console.print( f"❌ [red]We had a problem in the pipeline! \nThe image at '{image_path}' could not be found! \nSkipping... [/]" ) continue
def main(): parser = argparse.ArgumentParser() parser.add_argument('input', help='File to generate image from.') parser.add_argument( '-s', '--show', help='Show image using xdg-open when image is generated.', action='store_true') parser.add_argument('-b', '--blur', help='Blur the image', action='store_true') parser.add_argument( '--no_quantize', help= 'Do not quantize the image before processing (may make the image look better)', action='store_true') args = parser.parse_args() sInputImage = args.input sOutputPath = './nordified/' + path.splitext( path.basename(sInputImage))[0] + '-nordified.jpg' print(f"Writing nordified version to {sOutputPath}..") go_nord = GoNord() image = go_nord.open_image(sInputImage) if args.blur: image = image.filter(ImageFilter.GaussianBlur(5)) go_nord.set_default_nord_palette() #go_nord.disable_avg_algorithm() image = go_nord.quantize_image(image, save_path=sOutputPath) #go_nord.convert_image(image, save_path=sOutputPath) # To base64 #go_nord.image_to_base64(image, 'jpeg') print("Done.") if args.show: run('xdg-open {}'.format(sOutputPath), shell=True)
#!/usr/bin/env python import argparse from ImageGoNord import GoNord parser = argparse.ArgumentParser( description='convert image palette to specified palette') parser.add_argument('colorscheme', type=str, help='name of the colorscheme') parser.add_argument('image', type=str, help='path to the image') args = parser.parse_args() path = "/home/samy/.config/colorschemes/" + args.colorscheme with open(path, 'r') as f: lines = f.readlines() colors = [line.split()[2] for line in lines] go_nord = GoNord() go_nord.reset_palette() for color in colors: go_nord.add_color_to_palette(color) print(args.image) image = go_nord.open_image(args.image) go_nord.convert_image(image, save_path='/home/samy/Wallpapers/wall.png')
def test_resize_image(image: Image, go_nord: GoNord): resized_image = go_nord.resize_image(image) w, h = image.size assert resized_image.size == (round(w / 2), round(h / 2))
def test_resize_image_with_size(image, go_nord: GoNord): resized_image = go_nord.resize_image(image, size=(20, 20)) assert resized_image.size == (20, 20)
def test_resize_image_with_w_and_h(image, go_nord: GoNord): resized_image = go_nord.resize_image(image, w=20, h=20) assert resized_image.size == (20, 20)
def go_nord(): return GoNord()
from ImageGoNord import NordPaletteFile, GoNord go_nord = GoNord() """image = go_nord.open_image("images/test-profile.jpg") go_nord.convert_image(image, save_path='images/test.processed.jpg') """ # E.g. Avg algorithm and less colors go_nord.enable_avg_algorithm() go_nord.reset_palette() # go_nord.add_file_to_palette(NordPaletteFile.POLAR_NIGHT) # go_nord.add_file_to_palette(NordPaletteFile.SNOW_STORM) # go_nord.add_color_to_palette('#FF0000') go_nord.set_default_nord_palette() image = go_nord.open_image("images/test.jpg") go_nord.convert_image(image, save_path='images/test.avg.jpg') # E.g. Resized img no Avg algorithm and less colors go_nord.disable_avg_algorithm() go_nord.reset_palette() go_nord.add_file_to_palette(NordPaletteFile.POLAR_NIGHT) go_nord.add_file_to_palette(NordPaletteFile.SNOW_STORM) image = go_nord.open_image("images/test.jpg") resized_img = go_nord.resize_image(image) go_nord.convert_image(resized_img, save_path='images/test.resized.jpg') # E.g. Quantize image = go_nord.open_image("images/test.jpg") go_nord.reset_palette()
wallpaper_ids = [sub['uniqid'] for sub in wallpaper_submissions] ign_ids = [sub['uniqid'] for sub in ign_submissions] wallpapers_to_process = [ x for x in wallpaper_submissions if x['uniqid'] not in ign_ids ] print('Wallpaper processabili e unici: ' + str(len(wallpapers_to_process))) if len(wallpapers_to_process) > 0: published_post = 0 for sub in wallpapers_to_process: if published_post >= MAX_POST_TO_PUBLISH: break go_nord = GoNord() go_nord.set_default_nord_palette() go_nord.enable_avg_algorithm() for palette_key in FLAIR: go_nord.reset_palette() IGN_TITLE_PREFIX = '[' + palette_key + '] ' for hex_color in FLAIR[palette_key]['hex_colors']: go_nord.add_color_to_palette(hex_color) im = go_nord.base64_to_image( base64.b64encode(requests.get(sub['url']).content)) img_path = 'images/' + sub['uniqid'] + '.' + sub['url'][-3:] print('Processing ' + sub['title']) try:
args = sys.argv[1:] if len(args) == 0: print(__doc__) sys.exit(1) # If help given then print the docstring of the module and exit if "--help" in args or "-h" in args: print(__doc__) sys.exit(0) if "--version" in args or "-v" in args: print(VERSION) sys.exit(0) go_nord = GoNord() IMAGE_ARGUMENT_PATTERN = r'-(-img|i)=*' IS_IMAGE_PASSED = False for arg in args: searched_arg = re.search(IMAGE_ARGUMENT_PATTERN, arg) if searched_arg is not None: IS_IMAGE_PASSED = True break if not IS_IMAGE_PASSED: to_console(confarg.logs["img"][1].format(arg), confarg.logs["img"][-1], confarg.logs["err"][0]) sys.exit(1) QUIET_MODE = "-q" in args or "--quiet" in args
def main(): dirOld = "/home/mir/Pictures/wallhaven/" dirNew = "/home/mir/Pictures/newWall/" for root, dirs, files in os.walk(dirOld): for file in files: imagePath = dirOld + file name = file.split(".", 1) oName = name[0] + "-Nord." + name[1] savePath = dirNew + oName # E.g. Replace pixel by pixel go_nord = GoNord() image = go_nord.open_image(imagePath) go_nord.convert_image(image, save_path=savePath) # E.g. Avg algorithm and less colors go_nord.enable_avg_algorithm() go_nord.reset_palette() go_nord.add_file_to_palette(NordPaletteFile.POLAR_NIGHT) go_nord.add_file_to_palette(NordPaletteFile.SNOW_STORM) # You can add color also by their hex code go_nord.add_color_to_palette("#FF0000") image = go_nord.open_image(imagePath) go_nord.convert_image(image, save_path=savePath) # E.g. Resized img no Avg algorithm and less colors go_nord.disable_avg_algorithm() go_nord.reset_palette() go_nord.add_file_to_palette(NordPaletteFile.POLAR_NIGHT) go_nord.add_file_to_palette(NordPaletteFile.SNOW_STORM) image = go_nord.open_image(imagePath) resized_img = go_nord.resize_image(image) go_nord.convert_image(resized_img, save_path=savePath) # E.g. Quantize image = go_nord.open_image(imagePath) go_nord.reset_palette() go_nord.set_default_nord_palette() quantize_image = go_nord.quantize_image(image, save_path=savePath) # To base64 go_nord.image_to_base64(quantize_image, "jpeg")
def setup_instance(req): go_nord = GoNord() hex_colors = [] if req.form.get('colors'): hex_colors = req.form.get('colors').split(',') if len(hex_colors) > 0: go_nord.reset_palette() for hex_color in hex_colors: go_nord.add_color_to_palette(hex_color) if req.form.get('is_avg'): go_nord.enable_avg_algorithm() if req.form.get('avg_box_width') and req.form.get('avg_box_height'): go_nord.set_avg_box_data(int(req.form.get('avg_box_width')), int(req.form.get('avg_box_height'))) if req.form.get('blur'): go_nord.enable_gaussian_blur() return go_nord