File size: 2,572 Bytes
ba2ef65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import argparse
from PIL import Image

def get_head_uvs():
    """
    Returns the (x, y, w, h) of each 2D texture block of the head.
    """
    head_uvs = []
    
    # [ [ [size, offset], ... ], decor_offset ]
    part = [
        [
            [(8,8,8),(8,8)],  # front
            [(8,8,8),(24,8)], # back
            [(8,8,8),(16,8)], # left
            [(8,8,8),(0,8)],  # right
            [(8,8,8),(8,0)],  # top
            [(8,8,8),(16,0)], # bottom
        ], (32,0)
    ]
    
    decor_offset = part[1]
    
    for size_info, offset in part[0]:
        # Take the first two values from the 3D size (dx, dy, dz) as the width and height of the 2D texture map
        w, h = size_info[0], size_info[1]
        
        # Base head area
        head_uvs.append((offset[0], offset[1], w, h))
        
        # Head decoration (decor) area
        decor_x = offset[0] + decor_offset[0]
        decor_y = offset[1] + decor_offset[1]
        head_uvs.append((decor_x, decor_y, w, h))
        
    return head_uvs

def merge_skins(skin_a_path, skin_b_path, output_path):
    # Open images and ensure they have an alpha channel
    img_a = Image.open(skin_a_path).convert("RGBA")
    img_b = Image.open(skin_b_path).convert("RGBA")
    
    # Check if dimensions are compatible
    if img_a.size != img_b.size:
        print(f"Warning: Skin A ({img_a.size}) and Skin B ({img_b.size}) sizes do not match.")
    
    # Use B (provides body and limbs) as the base background
    img_c = img_b.copy()
    
    # Get head regions that need to be copied from A
    head_uvs = get_head_uvs()
    
    for x, y, w, h in head_uvs:
        box = (x, y, x + w, y + h)
        
        # Crop the corresponding head block from A
        region_a = img_a.crop(box)
        
        # Paste onto C. Do not use mask to ensure complete coverage (including transparent pixels covering B's original pixels)
        img_c.paste(region_a, box)

    img_c.save(output_path)
    print(f"Successfully merged: A's head ({skin_a_path}) + B's body/limbs ({skin_b_path}) -> {output_path}")

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Combine skins: Take the head of Skin A and the body and limbs of Skin B.")
    parser.add_argument("skin_a", help="Path to Skin A (provides the head)")
    parser.add_argument("skin_b", help="Path to Skin B (provides the body and limbs)")
    parser.add_argument("-o", "--output", default="skin_c.png", help="Output path for Skin C")
    args = parser.parse_args()
    
    merge_skins(args.skin_a, args.skin_b, args.output)