tee_morphosis

A library for parsing, splitting, and building Tee skins.
This crate provides tools for parsing a source Tee skin image into its constituent parts (body, feet, hands, eyes, etc.) and then composing them into a final character image with various expressions.
Features
net: Enables network requests (loading skins from URLs) using Tee::new_from_url.
Installation
Add this to your Cargo.toml:
[dependencies]
tee_morphosis = "1.3.0"
To use network capabilities (loading skins from URLs), enable the net feature:
[dependencies]
tee_morphosis = { version = "1.3.0", features = ["net"] }
How to Use
Example: Creating a skin from a local file
Here's a simple example of how to read a skin file, create a character with "happy" eyes, and save the result to a new file.
use std::fs;
use bytes::Bytes;
use tee_morphosis::tee::{
Tee,
parts::EyeType,
uv::TEE_UV_LAYOUT,
skin::TEE_SKIN_LAYOUT,
};
use image::ImageFormat;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let skin_data = fs::read("path/to/your_skin.png")?;
let tee = Tee::new(
Bytes::from(skin_data),
TEE_UV_LAYOUT,
ImageFormat::Png,
)?;
let eye_type = EyeType::Happy;
let image_bytes = tee.compose(
TEE_SKIN_LAYOUT,
eye_type,
ImageFormat::Png,
)?;
fs::write("composed_tee.png", &image_bytes)?;
println!("Skin successfully created and saved to composed_tee.png");
Ok(())
}
Example: Tee color rotating
Here's a simple example of how to change color with DDNet color value (or hls)
use std::fs;
use bytes::Bytes;
use tee_morphosis::tee::{
Tee,
hsl::ddnet_color_to_hsl,
parts::TeePart
};
use image::ImageFormat;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let skin_data = fs::read("path/to/your_skin.png")?;
let mut tee = Tee::new(
Bytes::from(skin_data),
TEE_UV_LAYOUT,
ImageFormat::Png,
)?;
let hsl = ddnet_color_to_hsl(1900500);
tee.apply_hsl_to_all(hsl);
tee.apply_hsl_to_parts(hsl, &[TeePart::Body, TeePart::BodyShadow]);
let composed = tee.compose_png(TEE_SKIN_LAYOUT, ImageFormat::Png)?;
fs::write("colored_composed_tee.png", &composed)?;
println!("Skin successfully created, colored and saved to colored_composed_tee.png");
Ok(())
}
Example: Loading and creating a skin from a URL (with net feature)
This example demonstrates how to fetch a skin from the internet and assemble it.
use tee_morphosis::tee::{
Tee,
parts::EyeType,
uv::TEE_UV_LAYOUT,
skin::TEE_SKIN_LAYOUT,
};
use std::fs;
use image::ImageFormat;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let tee = Tee::new_from_url(
"https://teedata.net/databasev2/skins/glow_rainbow/glow_rainbow.png",
TEE_UV_LAYOUT,
).await?;
let image_bytes = tee.compose(
TEE_SKIN_LAYOUT,
EyeType::Surprise,
ImageFormat::Png,
)?;
fs::write("composed_from_url.png", &image_bytes)?;
println!("Skin successfully downloaded and saved to composed_from_url.png");
Ok(())
}
License
This project is licensed under the MIT License.