Image converter for MicroPython

I wrote a script that takes .c files generated using ht e lvgl online image converter

and turns it into a binary data file. This reduces the amount of storage space used to store the image data. The script also generates a python file that you would load onto your MCU along with the binary files. The generated python file is easy to use

from image_loader import ImageLoader
image_loader = ImageLoader()

img = lv.img(lv.scr_act())
img.set_src(image_loader.name_of_image)

garbage collection is done once the image data it loaded. I do this because of how large the image data can be. Also depending on how many images you have stored there is a container that holds the height, width and format information that loads when you load an image. I did not set that information at the module level because in most use cases images only get loaded a single time and that is typically at startup so there is no point in having it kicking about using up memory. The script can easily be modified to change where that information is located if a user wants to.

If you run the script from the command line you have the option to pass an absolute path to a directory or a file. If a directory is passed then the contents of the directory is searched for files that can be converted. You can also optionally supply an absolute output path. This must always be a directory if one is supplied. if you do not provide a destination path then the current working directory is used. if no source path is supplied the current working directory is used. You must supply a source path to be able to supply a destination path.

mpy_image.zip (1.3 KB)

Remember to convert your images first using the online image converter and then run the script to convert the files.