Created
December 15, 2023 22:57
-
-
Save auzden/9bea709c4fb1985849a3dcc46cdcb4e4 to your computer and use it in GitHub Desktop.
Walnut App Icon Embed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
def make_embed(in_png_file, out_file_name): | |
with open(in_png_file, "rb") as file: | |
png_data = file.read() | |
with open(out_file_name, "w") as file: | |
file.write("const uint8_t g_WalnutIcon[] =\n{\n") | |
count = 0 | |
length = len(png_data) | |
for index in range(length): | |
byte = png_data[index] | |
file.write(f'0x{byte:02X}') | |
if index == length - 1: | |
break | |
count = count + 1 | |
if count < 16: | |
file.write(', ') | |
else: | |
file.write(',\n') | |
count = 0 | |
file.write("\n};") | |
print(f'Wrote {length} bytes to {out_file_name}') | |
def usage(): | |
print("usage: python make-walnut-icon.py [path-to-png-file]") | |
def main(): | |
arg_count = len(sys.argv) | |
if (arg_count != 2): | |
usage() | |
return | |
in_png_file = sys.argv[1] | |
if not os.path.exists(in_png_file): | |
print(f'{in_png_file} does not exist.') | |
return | |
out_file_name = 'Walnut-Icon.embed' | |
make_embed(in_png_file, out_file_name) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment