Recolor white-hair assets & composite avatars
Project description
Avatar Creator Core
A Python library for recoloring white-hair assets and compositing avatar images using Pillow.
Features
- Recolor hair images to any RGB color while preserving shading.
- Composite hair and face images to create custom avatars.
- Simple API for loading, recoloring, and merging images.
Installation
pip install avatar-creator-core==1.0.0
Usage
Example script (cli/main.py):
import os
import avatar_creator.core as core
hair_file = os.path.join("content/hair", "mid-length.png")
face_file = os.path.join("content/face", "face_1.png")
# Load images
face_img = core.load_rgba_image(face_file)
hair_img = core.load_rgba_image(hair_file)
# Recolor hair to orange
hair_img = core.recolor_to_rgb(hair_img, (255, 144, 25))
# Composite hair over face
avatar = core.merge_images(face_img, hair_img)
# Save result
avatar.save("output.png")
Example: Creating a blue-haired avatar
import os
import avatar_creator.core as core
face_img = core.load_rgba_image(
os.path.join("content/face", "face_2.png")
)
hair_img = core.load_rgba_image(
os.path.join("content/hair", "short.png")
)
hair_img = core.recolor_to_rgb(hair_img, (50, 100, 255)) # Blue
avatar = core.merge_images(face_img, hair_img)
avatar.save("avatar-blue.png")
Example: Batch generate avatars with different hair colors
import os
import avatar_creator.core as core
colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)] # Red, Green, Blue
face_img = core.load_rgba_image(
os.path.join("content/face", "face_1.png")
)
hair_img = core.load_rgba_image(
os.path.join("content/hair", "mid-length.png")
)
for color in colors:
recolored = core.recolor_to_rgb(hair_img, color)
avatar = core.merge_images(face_img, recolored)
avatar.save(f"avatar-{color[0]}-{color[1]}-{color[2]}.png")
Example Images
| Face Example | Hair Example | Resulting Avatar Example |
|---|---|---|
If running the cli/main.py Place your face and hair images in the cli/content/face/ and cli/content/hair/ folders, respectively.
API
avatar_creator.core.recolor_to_rgb
recolor_to_rgb(img: Image.Image, target_rgb: tuple[int, int, int]) -> Image.Image
Recolors an RGBA image to the target RGB color, preserving the original brightness.
avatar_creator.core.load_rgba_image
load_rgba_image(file_path_: str) -> Image.Image
Loads an image from a directory and converts it to RGBA.
avatar_creator.core.merge_images
merge_images(base_img: Image.Image, *images: Image.Image) -> Image.Image
Alpha-composites multiple RGBA images. All images must be the same size.
License
MIT License. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file avatar_creator_core-1.0.1.tar.gz.
File metadata
- Download URL: avatar_creator_core-1.0.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1557a0cde62f51710f4bfa04c4468563321f22bea85456efba1e95d009eb3e3
|
|
| MD5 |
2e6dddc5ff4631f5205ac9f61fd892b4
|
|
| BLAKE2b-256 |
078c33b1306d86e238eec62f4ab91e51386b9e449e212d74b99952ec2650ee39
|
File details
Details for the file avatar_creator_core-1.0.1-py3-none-any.whl.
File metadata
- Download URL: avatar_creator_core-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02ef0b264a94465b5042cdc319984ffc5a40f315b1a614a419bcdb15ce279f01
|
|
| MD5 |
7e336671996d9ee80969d0f892be5a1c
|
|
| BLAKE2b-256 |
4b567568551940127ac3b41bfef4bd37a6130fb35a9d120302bdb833c37f266b
|