#!/bin/bash

# Renkleri parametre olarak al
tshirt_color=$1
skin_tone=$2
hair_model=$3
hair_color=$4
output=$5

# Geçici dosyalar oluştur
temp_body="temp_body.png"
temp_face="temp_face.png"
temp_hair="temp_hair.png"
temp_background="temp_background.png"

# 1. Body'yi renklendir (Doygunluk %100, Parlaklık %100)
convert ./base/body.png -fill "$tshirt_color" -colorize 15% -modulate 60,60,100 "$temp_body"

# 2. Yüzü renklendir (Doygunluk %100, Parlaklık %100)
convert ./base/head.png -alpha on -fill "$skin_tone" -colorize 25% -modulate 60,60,100 "$temp_face"

# 3. Saç modelini ve rengini uygulama (Doygunluk %100, Parlaklık %100)
convert ./hairs/"$hair_model.png" -alpha on -fill "$hair_color" -colorize 15% -modulate 40,60,100 "$temp_hair"

# 4. Beyaz arka plan oluştur ve %25 opaklıkla ekle
convert -size 1024x1024 xc:white -alpha set -channel A -evaluate set 15% "$temp_background"

# 5. Tüm katmanları birleştir
convert "$temp_body" "$temp_face" -compose over -composite "temp1.png"
convert "temp1.png" "$temp_hair" -compose over -composite "temp2.png"
convert "temp2.png" "./base/face.png" -compose over -composite "temp3.png"
convert "$temp_background" "temp3.png" -compose over -composite -modulate 100,250,100 "$output"

# Geçici dosyaları temizle
rm "$temp_body" "$temp_face" "$temp_hair" "temp"*".png"

echo "Created Avatar: $output"

