Guest User

Untitled

a guest
Jun 17th, 2025
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.15 KB | Source Code | 0 0
  1. """
  2. Note: this needs the 'MapSkin2.png' in the same directory
  3. """
  4.  
  5. from PIL import Image
  6. import numpy as np
  7.  
  8. def hex_to_rgb(hex_color):
  9.     """Convert hex color string (e.g., 'FF0000') to an (R, G, B) tuple."""
  10.     hex_color = hex_color.lstrip('#')
  11.     return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
  12.  
  13. def rgb_to_hex(rgb):
  14.     """Convert RGB color string (e.g., 'FF0000') to hex color string."""
  15.     return '#%02x%02x%02x' % rgb
  16.  
  17. def map_image(src_path, map_path, mapping_rules, output_path):
  18.     src_img = Image.open(src_path).convert("RGB")
  19.     map_img = Image.open(map_path).convert("RGB")
  20.  
  21.     src = np.array(src_img)
  22.     map_data = np.array(map_img)
  23.  
  24.     h2, w, _ = src.shape
  25.     h1 = 4096  # You can change this depending on your need
  26.  
  27.     diff = h2 - h1
  28.     dest = src[h2 - h1:].copy()
  29.  
  30.     # Create a reverse color map: RGB tuple -> (dx, dy)
  31.     rule_map = {hex_to_rgb(k): v for k, v in mapping_rules.items()}
  32.     found = set()
  33.  
  34.     for y in range(h2):
  35.         for x in range(w):
  36.             color = tuple(map_data[y, x])
  37.             if color in rule_map:
  38.                 dx, dy = rule_map[color]
  39.                 dest_y = y + dy - diff
  40.                 dest_x = x + dx
  41.                 if 0 <= dest_y < h1 and 0 <= dest_x < w:
  42.                     dest[dest_y, dest_x] = src[y, x]
  43.                     if color not in found:
  44.                         found.add(color)
  45.                         print("Found rule: ", rgb_to_hex(color))
  46.  
  47.     Image.fromarray(dest).save(output_path)
  48.     print(f"Mapped image saved to {output_path}")
  49.  
  50. # Example usage
  51. if __name__ == "__main__":
  52.     mapping_rules = {
  53.         # flap thing
  54.         "FA00FF": (174 - 1357, 4127 - 235),
  55.         "0079ff": (174 - 1357, 4127 - 235),
  56.         "00F0FF": (174 - 1357, 4127 - 235),
  57.         # air intake
  58.         "FF8500": (2544 - 650, 0),
  59.         # owheel ? FFE400
  60.         "FFE500": (2867-3128, 1081 - 10),
  61.         # iwheel ? FFEE5E
  62.         "FFEF5E": (333-8, 1118-34),
  63.         # covers ? FFF38E
  64.         "FFF48E": (0, 2595-850),
  65.     }
  66.  
  67.     source = "PATH/TO/IMAGE.png"
  68.     dest = "PATH/TO/OUTPUT.png"
  69.     map_image(source, "MapSkin2.png", mapping_rules, dest)
  70.  
Advertisement
Add Comment
Please, Sign In to add comment