Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Note: this needs the 'MapSkin2.png' in the same directory
- """
- from PIL import Image
- import numpy as np
- def hex_to_rgb(hex_color):
- """Convert hex color string (e.g., 'FF0000') to an (R, G, B) tuple."""
- hex_color = hex_color.lstrip('#')
- return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
- def rgb_to_hex(rgb):
- """Convert RGB color string (e.g., 'FF0000') to hex color string."""
- return '#%02x%02x%02x' % rgb
- def map_image(src_path, map_path, mapping_rules, output_path):
- src_img = Image.open(src_path).convert("RGB")
- map_img = Image.open(map_path).convert("RGB")
- src = np.array(src_img)
- map_data = np.array(map_img)
- h2, w, _ = src.shape
- h1 = 4096 # You can change this depending on your need
- diff = h2 - h1
- dest = src[h2 - h1:].copy()
- # Create a reverse color map: RGB tuple -> (dx, dy)
- rule_map = {hex_to_rgb(k): v for k, v in mapping_rules.items()}
- found = set()
- for y in range(h2):
- for x in range(w):
- color = tuple(map_data[y, x])
- if color in rule_map:
- dx, dy = rule_map[color]
- dest_y = y + dy - diff
- dest_x = x + dx
- if 0 <= dest_y < h1 and 0 <= dest_x < w:
- dest[dest_y, dest_x] = src[y, x]
- if color not in found:
- found.add(color)
- print("Found rule: ", rgb_to_hex(color))
- Image.fromarray(dest).save(output_path)
- print(f"Mapped image saved to {output_path}")
- # Example usage
- if __name__ == "__main__":
- mapping_rules = {
- # flap thing
- "FA00FF": (174 - 1357, 4127 - 235),
- "0079ff": (174 - 1357, 4127 - 235),
- "00F0FF": (174 - 1357, 4127 - 235),
- # air intake
- "FF8500": (2544 - 650, 0),
- # owheel ? FFE400
- "FFE500": (2867-3128, 1081 - 10),
- # iwheel ? FFEE5E
- "FFEF5E": (333-8, 1118-34),
- # covers ? FFF38E
- "FFF48E": (0, 2595-850),
- }
- source = "PATH/TO/IMAGE.png"
- dest = "PATH/TO/OUTPUT.png"
- map_image(source, "MapSkin2.png", mapping_rules, dest)
Advertisement
Add Comment
Please, Sign In to add comment