GIF decoder

Allow to use of GIF images in LVGL. Based on

When enabled in lv_conf.h with LV_USE_GIF lv_gif_create(parent) can be used to create a gif widget.

lv_gif_set_src(obj, src) works very similarly to lv_img_set_src. As source It also accepts images as variables (lv_img_dsc_t) or files.

Convert GIF files to C array

To convert a GIF file to byte values array use LVGL's online converter. Select "Raw" color format and "C array" Output format.

Use GIF images from file

For example:

lv_gif_set_src(obj, "S:path/to/example.gif");

Note that, a file system driver needs to regsitered to open images from files. Read more about it here or just enable one in lv_conf.h with LV_USE_FS_...

Memory requirements

To decode and display a GIF animation the following amount of RAM is required:

  • LV_COLOR_DEPTH 8: 3 x image width x image height

  • LV_COLOR_DEPTH 16: 4 x image width x image height

  • LV_COLOR_DEPTH 32: 5 x image width x image height


Open a GIF image from file and variable

C code  

#include "../../lv_examples.h"

 * Open a GIF image from a file and a variable
void lv_example_gif_1(void)
    lv_obj_t * img;

    img = lv_gif_create(lv_scr_act());
    lv_gif_set_src(img, &img_bulb_gif);
    lv_obj_align(img, LV_ALIGN_LEFT_MID, 20, 0);

    img = lv_gif_create(lv_scr_act());
    /* Assuming a File system is attached to letter 'A'
     * E.g. set LV_USE_FS_STDIO 'A' in lv_conf.h */
    lv_gif_set_src(img, "A:lvgl/examples/libs/gif/bulb.gif");
    lv_obj_align(img, LV_ALIGN_RIGHT_MID, -20, 0);


MicroPython code  

 GitHub Simulator
Error encountered while trying to open /home/runner/work/lvgl/lvgl/examples/libs/gif/



lv_obj_t *lv_gif_create(lv_obj_t *parent)
void lv_gif_set_src(lv_obj_t *obj, const void *src)
void lv_gif_restart(lv_obj_t *gif)


const lv_obj_class_t lv_gif_class
struct lv_gif_t

Public Members

lv_img_t img
gd_GIF *gif
lv_timer_t *timer
lv_img_dsc_t imgdsc
uint32_t last_call