From e3f55b10b6a4ae797b359518ccf78d89454c70b2 Mon Sep 17 00:00:00 2001 From: NicklasVraa Date: Wed, 23 Aug 2023 22:51:22 +0200 Subject: [PATCH] Updated gui to support new features. --- color_manager/gui.py | 100 +++++++++++++++++++++++++++++++++++-------- readme.md | 34 +++++++++++++-- test.ipynb | 35 +++++++-------- 3 files changed, 131 insertions(+), 38 deletions(-) diff --git a/color_manager/gui.py b/color_manager/gui.py index 17d2fc7b..1c4122b2 100644 --- a/color_manager/gui.py +++ b/color_manager/gui.py @@ -10,23 +10,29 @@ import os, ngtk, utils def recolor(src_path, dest_path, name, replacement, progress_bar, status): """Recursively copies and converts a source folder into a destination, given a either a color or a palette.""" - new_colors, smooth, is_mono = utils.get_input_colors(replacement) + utils.check_path(src_path) + utils.check_path(dest_path) + + new_colors, smooth, op = utils.get_input_colors(replacement) dest_path = utils.copy_pack(src_path, dest_path, name) - svg_paths = utils.get_paths(dest_path, [".svg"]) - img_paths = utils.get_paths(dest_path, [".png", ".jpg", ".jpeg"]) - n = len(svg_paths); i = 0 - for path in svg_paths: - with open(path, 'r') as file: - svg = file.read() + # Recolor vector graphics. + paths = utils.get_paths(dest_path, [".svg", ".xml"]) + n = len(paths); i = 0 + for path in paths: + with open(path, 'r') as file: x = file.read() - colors = utils.get_svg_colors(svg) + x = utils.expand_all_hex(x) + colors = utils.get_file_colors(x) - if is_mono: svg = utils.monochrome_svg(svg, colors, new_colors) - else: svg = utils.multichrome_svg(svg, colors, new_colors) + if op == "color": + x = utils.apply_monotones_to_vec(x, colors, new_colors) + elif op == "palette": + x = utils.apply_palette_to_vec(x, colors, new_colors) + elif op == "mapping": + x = utils.apply_mapping_to_vec(x, colors, new_colors) - with open(path, 'w') as file: - file.write(svg) + with open(path, 'w') as file: file.write(x) i = i + 1 progress_bar.set_fraction(i/n) @@ -35,14 +41,72 @@ def recolor(src_path, dest_path, name, replacement, progress_bar, status): status.set_text("SVGs completed! Continuing...") - n = len(img_paths); i = 0 - for path in img_paths: - img = Image.open(path) + # Recolor stylesheets. + paths = utils.get_paths(dest_path, [".css", "rc"]) + n = len(paths); i = 0 + for path in paths: + with open(path, 'r') as file: x = file.read() - if is_mono: img = utils.monochrome_img(img, new_colors) - else: img = utils.multichrome_img(img, new_colors, smooth) + x = utils.css_to_hex(x) + x = utils.expand_all_hex(x) + colors = utils.get_file_colors(x) - img.save(path) + if op == "color": + x = utils.apply_monotones_to_vec(x, colors, new_colors) + elif op == "palette": + x = utils.apply_palette_to_vec(x, colors, new_colors) + elif op == "mapping": + x = utils.apply_mapping_to_vec(x, colors, new_colors) + + with open(path, 'w') as file: file.write(x) + + i = i + 1 + progress_bar.set_fraction(i/n) + while Gtk.events_pending(): + Gtk.main_iteration() + + # Recolor pngs. + paths = utils.get_paths(dest_path, [".png"]) + n = len(paths); i = 0 + for path in paths: + x = Image.open(path) + x = x.convert("RGBA") + a = x.split()[3] # Save original alpha channel. + + if op == "color": + x = utils.apply_monotones_to_img(x, new_colors) + elif op == "palette": + x = utils.apply_palette_to_img(x, new_colors, smooth) + elif op == "mapping": + x = utils.apply_mapping_to_img(x, new_colors, smooth) + + x = x.convert("RGBA") + r,g,b,_ = x.split() + x = Image.merge("RGBA",(r,g,b,a)) # Restore original alpha channel. + x.save(path) + + i = i + 1 + progress_bar.set_fraction(i/n) + while Gtk.events_pending(): + Gtk.main_iteration() + + + # Recolor jpgs. + paths = utils.get_paths(dest_path, [".jpg", ".jpeg"]) + n = len(paths); i = 0 + for path in paths: + x = Image.open(path) + x = x.convert("RGB") + + if op == "color": + x = utils.apply_monotones_to_img(x, new_colors) + elif op == "palette": + x = utils.apply_palette_to_img(x, new_colors, smooth) + elif op == "mapping": + x = utils.apply_mapping_to_img(x, new_colors, smooth) + + x = x.convert("RGB") + x.save(path) i = i + 1 progress_bar.set_fraction(i/n) diff --git a/readme.md b/readme.md index f70b460d..3c6a6267 100644 --- a/readme.md +++ b/readme.md @@ -21,7 +21,7 @@ Color Manager is a program for recoloring and manipulating existing icon packs, | **Monochrome**:
`(0.6,0.54,0.5)` | ![2](resources/wallpaper/mono.png) | | **Multichrome**:
`nord.json`
`smooth=false` | ![3](resources/wallpaper/multi_accurate.png) | | **Multichrome**:
`nord.json`
`smooth=true` | ![4](resources/wallpaper/multi_smooth.png) | -| **Remapping**:
`renord.json`
Remapped
previous to
alterate nord
colors. | ![5](resources/wallpaper/remapped.png) | +| **Remapping**:
`renord.json`
Remap of previous
to alterate nord
colors
. | ![5](resources/wallpaper/remapped.png) | | **Extraction**:
Original `num=10` | ![6](resources/wallpaper/palette.png) | With these tools, one can build a pipeline to customize most assets to fit into a larger design. @@ -45,10 +45,10 @@ With these tools, one can build a pipeline to customize most assets to fit into - [x] Adding basic geometry to the backgrounds of svg icons. - [x] Preserve transparency in pngs after multichrome recoloring. - [x] Add function to remap colors directly using a json dictionary. +- [x] Update GUI to support new features. - [ ] Optional automatic palette extending. - [ ] Basic framework for manipulating GTK, Cinnamon and Metacity themes. - [ ] Intelligent color inversion. -- [ ] Update GUI to support new features. - [ ] GNU/Linux binary (deb, flatpak, appimage). @@ -56,8 +56,9 @@ With these tools, one can build a pipeline to customize most assets to fit into Currently, three operations are supported: | Type | Result | Speed | Support | | :--: | ------ | ----- | ------- | -| **Monochrome recoloring** | A monochromatic variant, colored by appropriate shades of the provided base color. | ~5000svg/s
~500png/s | svg, xml, css, png, jpg | +| **Monochrome recoloring** | A monochromatic variant, colored by appropriate shades of the provided base color. | ~5050svg/s
~500png/s | svg, xml, css, png, jpg | | **Palette recoloring** | A multichromatic variant, where all colors are replaced by their nearest perceived equivalent that adheres to the provided color palette. | ~100svg/s
~3png/s | svg, xml, css, png, jpg | +| **Color remapping** | A multichromatic variant, where all colors that are specified in a given map will be replaced as dictated by said map. | ~1000svg/s
~10png/s | svg, xml, css, png, jpg | | **Extract colors** | Returns and optionally saves the color palette of an image, in specified detail. | ~10colors/s | svg, xml, css, png, jpg | | **Add backdrop** | Add a rectangular or elliptical background (and anything in between) to all svg icons. | ~5000svg/s | svg | @@ -107,6 +108,33 @@ utils.add_backdrop(src, dest, name, color, padding, rounding) Or launch the GUI by running `python3 color_manager/gui.py` in a terminal from the project's root directory. The GUI will adopt your active theme. Dependencies: `colormath`, `tqdm` and `pillow`. For the GUI, `pygobject` (GTK bindings) must also be installed. +**Defining a palette or mapping** is done in a json file, e.g.: +```json +{ + "type": "palette", + "name": "...", + "desc": "...", + "smooth": true/false, + "colors": [ + "#ffffff", + "#000000", + ... + ] +} +``` +```json +{ + "type": "mapping", + "name": "...", + "desc": "...", + "smooth": true/false, + "map": { + "#ffffff": "#000000", + "#f0f0f0": "#0f0f0f", + ... + } +} +``` ## Requests Until the release official release of Color Manager, I will be taking requests for recolorings. Simply submit a feature request, specifying what you would like to see. Please star the repository or consider donating, and I will upload your requested variant. Also consider showing the creators of the original artworks some love. diff --git a/test.ipynb b/test.ipynb index 10acc233..e4cd102e 100644 --- a/test.ipynb +++ b/test.ipynb @@ -2,9 +2,18 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The autoreload extension is already loaded. To reload it, use:\n", + " %reload_ext autoreload\n" + ] + } + ], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", @@ -14,38 +23,30 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "/home/nv/Downloads/my_pack/index.theme\n" + "/home/nv/Downloads/Soph/index.theme\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "svg: 100%|██████████| 6/6 [00:00<00:00, 1582.36it/s]\n", - "png: 0%| | 0/8 [00:00