Skip to content

Instantly share code, notes, and snippets.

@nikp123
Created August 16, 2021 22:27
Show Gist options
  • Save nikp123/100d2c7aa45236ea7aaca3562e57b73c to your computer and use it in GitHub Desktop.
Save nikp123/100d2c7aa45236ea7aaca3562e57b73c to your computer and use it in GitHub Desktop.
Get the difference between two photoshop pallete files and generates a Imagemagick conversion list
#!/usr/bin/env python3
from codecs import encode
import sys
def act_to_list(act_file):
with open(act_file, 'rb') as act:
raw_data = act.read() # Read binary data
hex_data = encode(raw_data, 'hex') # Convert it to hexadecimal values
total_colors_count = (int(hex_data[-7:-4], 16)) # Get last 3 digits to get number of colors total
misterious_count = (int(hex_data[-4:-3], 16)) # I have no idea what does it do
colors_count = (int(hex_data[-3:], 16)) # Get last 3 digits to get number of nontransparent colors
# Decode colors from hex to string and split it by 6 (because colors are #1c1c1c)
colors = [hex_data[i:i+6].decode() for i in range(0, total_colors_count*6, 6)]
# Add # to each item and filter empty items if there is a corrupted total_colors_count bit
colors = ['#'+i for i in colors if len(i)]
return colors, total_colors_count
original_file = sys.argv[1]
new_file = sys.argv[2]
original_colors, original_colors_count = act_to_list(original_file)
new_colors, new_colors_count = act_to_list(new_file)
#if original_colors_count != new_colors_count:
# print("Color counts dont match", original_colors_count, " != ", new_colors_count)
# Hack
if len(original_colors) > len(new_colors):
color_count = len(new_colors)
else:
color_count = len(original_colors)
for i in range(0, color_count):
if original_colors[i] != new_colors[i]:
print("-fill", original_colors[i], "-opaque", new_colors[i], end=" ")
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment