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
#!/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')
from ImageGoNord import NordPaletteFile, GoNord # E.g. Replace pixel by pixel go_nord = GoNord() image = go_nord.open_image("images/test.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) # You can add color also by their hex code go_nord.add_color_to_palette('#FF0000') 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