Skip to main content

Recolor white-hair assets & composite avatars

Project description

Avatar Creator Core

Build and Test Python Package

codecov

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 pillow

Or install from source:

pip install .

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

avatar_creator_core-1.0.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

avatar_creator_core-1.0.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file avatar_creator_core-1.0.0.tar.gz.

File metadata

  • Download URL: avatar_creator_core-1.0.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for avatar_creator_core-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c507b1a20470dfc98f4bd8c32e3c77d747d813eb271d587665e9af51ad34b341
MD5 af13cea37b80300c78568038ac03b822
BLAKE2b-256 b718772d2d31ff12eda237aa844aac66d89da02a73ead4b198d5142b1cdac382

See more details on using hashes here.

File details

Details for the file avatar_creator_core-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for avatar_creator_core-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 122b25bead3f65c2db4decd1ca9881c8f25df2b484e9d73b04c1eadf4e4da520
MD5 23a04ff50f3398e5976c3ef6832a0ba7
BLAKE2b-256 002fdee4d6f4094ffb5215f8d2691a8a66165ee36c95944786f0bca5bbab55bf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page