import struct, os, sys def _png_size(data): # PNG IHDR chunk at offset 16: 4 bytes width, 4 bytes height return struct.unpack_from('>II', data, 16) def png_to_ico(png_path, ico_path): with open(png_path, 'rb') as f: png_data = f.read() w, h = _png_size(png_data) png_data = png_data # full PNG data as icon payload header = struct.pack('