ValueError: tile cannot extend outside image

Was trying out the animation on a SSD1306.

animation:

  • file: “animation.gif”
    id: my_animation
    resize: 100x100

and when compiling got the ValueError as per the subject line. I’m not a developer so the Google results didn’t mean a lot to me.

Any idea what’s causing this?

Hi

Hard to know with based on the information you have given.

If you post you complete yaml file and the compile output. Then we can probably figure it out.

/Mattias

Txs for getting back.

Yaml file

esphome:
  name: ssd1306-display
  platform: ESP8266
  board: nodemcuv2

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "<password>"

wifi:
  ssid: "<ssid>"
  password: "<password>"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "<fallback ssid>"
    password: "<fallback password>"

captive_portal:

time:
  - platform: homeassistant
    id: esptime
    
image:
  - file: "image.png"
    id: my_image
    resize: 60x60
    
animation:
  - file: "walk-animation.gif"
    id: my_animation
    resize: 50x50

font:
  - file: "Amiko-Regular.ttf"
    id: font1
    size: 10
  - file: "Amiko-Bold.ttf"
    id: font2
    size: 14
  - file: "Amiko-SemiBold.ttf"
    id: font3
    size: 10

# Configuration for SSD1306
i2c:
  sda: D1
  scl: D2

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    reset_pin: D0
    address: 0x3C
    brightness: 50%
    lambda: |-
      it.strftime(64, 8, id(font1), TextAlign::CENTER, "%H:%M", id(esptime).now());

      it.print(0, 0, id(font1), "Time ");
      
      it.print(0, 54, id(font3), "Hello World!");
      
      // Draw a line from [97,0] to [110,50]
      it.line(97, 0, 115, 50);
      
      // Circles! Let's draw one with the center at [25,25] and a radius of 10
      it.circle(117, 25, 10);
      
      // Draw the image my_image at position [x=0,y=0]
      it.image(0, 25, id(my_image));
      
      //Ingress shown animation Frame.
      id(my_animation).next_frame();
      // Draw the animation my_animation at position [x=0,y=0]
      it.image(0, 0, id(my_animation), COLOR_ON, COLOR_OFF);

Output

INFO Reading configuration /config/esphome/ssd1306-display.yaml...
INFO Detected timezone 'AEST' with UTC offset 10 and daylight saving time from 03 October 02:00:00 to 03 April 03:00:00
INFO Generating C++ source...
Traceback (most recent call last):
  File "/usr/local/bin/esphome", line 33, in <module>
    sys.exit(load_entry_point('esphome', 'console_scripts', 'esphome')())
  File "/opt/esphome/esphome/__main__.py", line 760, in main
    return run_esphome(sys.argv)
  File "/opt/esphome/esphome/__main__.py", line 747, in run_esphome
    rc = POST_CONFIG_ACTIONS[args.command](args, config)
  File "/opt/esphome/esphome/__main__.py", line 343, in command_run
    exit_code = write_cpp(config)
  File "/opt/esphome/esphome/__main__.py", line 156, in write_cpp
    generate_cpp_contents(config)
  File "/opt/esphome/esphome/__main__.py", line 168, in generate_cpp_contents
    CORE.flush_tasks()
  File "/opt/esphome/esphome/core/__init__.py", line 616, in flush_tasks
    self.event_loop.flush_tasks()
  File "/opt/esphome/esphome/coroutine.py", line 245, in flush_tasks
    next(task.iterator)
  File "/opt/esphome/esphome/__main__.py", line 148, in wrapped
    await coro(conf)
  File "/opt/esphome/esphome/components/animation/__init__.py", line 89, in to_code
    frame = image.convert("1", dither=Image.NONE)
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 915, in convert
    self.load()
  File "/usr/lib/python3/dist-packages/PIL/ImageFile.py", line 215, in load
    decoder.setimage(self.im, extents)
ValueError: tile cannot extend outside image

Yet the device is only 64 pixels high.

Hi.

The error comes from when it try to resize the animations.
Esphome is trying to make it 50x50. This is before it has started to compile.

What’s the size of the animation gif.

/Mattias

The animation file is 650x727. So does the max of the file have to be like the device; i.e. not bigger than 128x64 in my case?

I have successfully scaled the still image (image.png, 333x151) so I thought to apply the same logic.

Hi.

I have tested to do the same with an animated gif. I get the same error. My esphome install is rather old though.
Maybe try to resize it by some other tool so you dont have to use the resize function.

/Mattias

Oh ok.

I have resized the file outside ESPHome to the right dimensions and it now loads although the animation is rather slow. But I figure that’s an issue with the processing power rather than ESPHome.

I’ll raise an issue when I find a minute as my ESPHome is the most recent version