Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abhishtagatya/paleta
🎨 Palette Extraction and Management Tool for Game Assets
https://github.com/abhishtagatya/paleta
color image-processing palette tools
Last synced: about 11 hours ago
JSON representation
🎨 Palette Extraction and Management Tool for Game Assets
- Host: GitHub
- URL: https://github.com/abhishtagatya/paleta
- Owner: abhishtagatya
- Created: 2024-03-26T22:01:03.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-05-03T10:45:11.000Z (7 months ago)
- Last Synced: 2024-11-06T23:47:08.417Z (11 days ago)
- Topics: color, image-processing, palette, tools
- Language: Python
- Homepage:
- Size: 103 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Paleta [![PyPI version](https://badge.fury.io/py/paleta.svg)](https://badge.fury.io/py/paleta)
Paleta is a Color Pallet Extraction and Management Tool that is focused on enhancing Visual Game Assets. It supports pallet conversion, mixing, minimizing, and matching in any way possible.
### Quick Guide
```python
from paleta.color import Color
from paleta.palette import Palette
from paleta.image import export_palette, extract_convert_palette# Initializing Colors
red = Color.from_hex("#F00")
green = Color.from_hex("#0F0")
blue = Color.from_hex("#00F")# Operations on Color
magenta = red + blue
yellow = red + green
cyan = green + blueprint(magenta.rgba) # Get RGBA value
print(yellow.to_lightness()) # To 0...255 Value
print(cyan.to_hsl()) # Get HSL Valuemagenta += 10 # Add 10 across values of RGB
cyan -= (10, 0, 10) # Subtract 10 across R and B valuetwilight_5 = Palette(
Color.from_hex("fbbbad"),
Color.from_hex("ee8695"),
Color.from_hex("4a7a96"),
Color.from_hex("333f58"),
Color.from_hex("292831")
) # Create a Palette Classtw = Palette.from_lospec("twilight-5") # Or use the Lospec API
assert (twilight_5.colors == tw.colors) # They're the same
twilight_5.add(yellow) # Add yellow to the palette
twilight_5.remove(yellow) # And Remove itwarm_ochre = Palette.from_lospec("warm-ochre")
the_after = Palette.from_lospec("the-after")twilight_5.union(warm_ochre) # Combine Palette Sets
twilight_5.intersection(the_after) # Or find where they intersectextract_convert_palette("ref.png", "palette.png", f_out="new_ref.png") # Map a Palette to an Image
export_palette(warm_ochre, f="warm-ochre.png") # Export a Created or Imported Palette
```The script above shows the basics for simple use of this package. Simply, it
treats Colors as a Vector(R, G, B, Alpha[Optional=255]) and a Palette as a Set of
Colors with all basic set operations.---
### Going Deeper
#### Mapping Palettes
```python
from paleta.palette import Palette
from paleta.palette import ConversionPalette
from paleta.metric import euclidean_distance, cosine_distance, cosine_similaritywarm_ochre = Palette.from_lospec("warm-ochre")
the_after = Palette.from_lospec("the-after")# Will create a Dictionary of how Palette (Warm Ochre) be mapped with Palette (The After)
# Using a Euclidean Distance Function and the Metric of Minimum Distance
cmap = ConversionPalette.map(warm_ochre, the_after, algo=euclidean_distance, metric=min)
print(cmap.to_dict())# Making your own function works
def some_distance_function() -> float:
# Map by distance
return float()def some_metric_function() -> object:
# Find Max Value
return max()cmap2 = ConversionPalette.map(warm_ochre, the_after, algo=some_distance_function, metric=some_metric_function)
print(cmap2.to_dict())# Randomize the Mapping
cmap3 = ConversionPalette.random(warm_ochre, the_after)
print(cmap3.to_dict())
```#### Minimize or Maximize Palette
```python
from paleta.palette import Palette
from paleta.palette import minimize_by_average, maximize_by_averagewarm_ochre = Palette.from_lospec("warm-ochre")
the_after = Palette.from_lospec("the-after")# Reduce the Palette by Averaging Neighboring Colors
min_warm_ochre = minimize_by_average(warm_ochre)
print(warm_ochre.color_set)
print(minimize_by_average(warm_ochre).color_set)
print(len(min_warm_ochre))# Increase the Palette by Adding the Averaging of Neighboring Colors
max_the_after = minimize_by_average(the_after)
print(the_after.color_set)
print(minimize_by_average(the_after).color_set)
print(len(max_the_after))
```