Skip to main content

Avatar Creator Core

Build and Test Python Package codecov PyPI

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
face_1.png mid-length.png output.png

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.

Metadata

Release files for avatar-creator-core 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for avatar-creator-core 1.0.1
File Size Uploaded
avatar_creator_core-1.0.1.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for avatar-creator-core 1.0.1
File Interpreter ABI Platform
avatar_creator_core-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.1 kB

Release files / avatar_creator_core-1.0.1.tar.gz

Download URL avatar_creator_core-1.0.1.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a1557a0cde62f51710f4bfa04c4468563321f22bea85456efba1e95d009eb3e3
BLAKE2b-256 checksum
How to use checksums
078c33b1306d86e238eec62f4ab91e51386b9e449e212d74b99952ec2650ee39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / avatar_creator_core-1.0.1-py3-none-any.whl

Download URL avatar_creator_core-1.0.1-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02ef0b264a94465b5042cdc319984ffc5a40f315b1a614a419bcdb15ce279f01
BLAKE2b-256 checksum
How to use checksums
4b567568551940127ac3b41bfef4bd37a6130fb35a9d120302bdb833c37f266b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page