mirror of
https://github.com/NicklasVraa/Color-manager.git
synced 2026-01-18 17:27:20 +01:00
Updated gui to support new features.
This commit is contained in:
@@ -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)
|
||||
|
||||
34
readme.md
34
readme.md
@@ -21,7 +21,7 @@ Color Manager is a program for recoloring and manipulating existing icon packs,
|
||||
| **Monochrome**:<br>`(0.6,0.54,0.5)` |  |
|
||||
| **Multichrome**:<br>`nord.json`<br>`smooth=false` |  |
|
||||
| **Multichrome**:<br>`nord.json`<br>`smooth=true` |  |
|
||||
| **Remapping**:<br>`renord.json`<br>Remapped<br>previous to<br>alterate nord <br>colors. |  |
|
||||
| **Remapping**:<br>`renord.json`<br><small>Remap of previous<br>to alterate nord<br>colors</small>. |  |
|
||||
| **Extraction**:<br>Original `num=10` |  |
|
||||
|
||||
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<br> ~500png/s | svg, xml, css, png, jpg |
|
||||
| **Monochrome recoloring** | A monochromatic variant, colored by appropriate shades of the provided base color. | ~5050svg/s<br> ~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<br> ~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<br> ~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 <a name="requests"></a>
|
||||
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.
|
||||
|
||||
35
test.ipynb
35
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<?, ?it/s]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"png: 100%|██████████| 8/8 [00:11<00:00, 1.46s/it]\n",
|
||||
"jpg: 100%|██████████| 1/1 [00:04<00:00, 4.32s/it]\n"
|
||||
"svg: 100%|██████████| 7974/7974 [00:01<00:00, 5077.70it/s]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"src = \"test/graphics\" # Also try \"test/theme\"\n",
|
||||
"name = \"my_pack\"\n",
|
||||
"src = \"~/Downloads/NovaOS-nord-icons\" # Also try \"test/theme\"\n",
|
||||
"name = \"Soph\"\n",
|
||||
"dest = \"~/Downloads\"\n",
|
||||
"color = (0.6, 0.54, 0.5) # = rc.normalize_hsl(180, 50, 50)\n",
|
||||
"color = (0.6, 0.54, 0.5) # = rc.normalize_hsl(180, 50, 50)\n",
|
||||
"color = utils.norm_hsl(234, 65, 65)\n",
|
||||
"palette = \"palettes/nord.json\"\n",
|
||||
"mapping = \"mappings/renord.json\"\n",
|
||||
"\n",
|
||||
|
||||
Reference in New Issue
Block a user