import os from os import abort from header import getOutputDir from PIL import Image def parseImage(imagePath): print(f"Parsing image: {imagePath}") if not os.path.isfile(imagePath): abort(f"Error: Image file {imagePath} does not exist") outputFile = os.path.join(getOutputDir(), f"image_{os.path.basename(imagePath)}.h") dataOut = "" dataOut += f"// Auto-generated image header for {os.path.basename(imagePath)}\n" dataOut += f"#pragma once\n" dataOut += f"#include \"asset/assetimage.h\"\n\n" name = os.path.splitext(os.path.basename(imagePath))[0] name = name.upper().replace(' ', '_') dataOut += f"static const assetimage_t IMAGE_{name} = {{\n" try: with Image.open(imagePath) as img: width, height = img.size dataOut += f" .width = {width},\n" dataOut += f" .height = {height},\n" except Exception as e: abort(f"Error: Unable to open image {imagePath}: {e}") dataOut += f"}};\n" with open(outputFile, 'w') as f: f.write(dataOut) return [ outputFile ]