How can I make "esp32_camera_web_server" generate png snapshots?

I have an ESP-EYE which includes this code:

esp32_camera:
  id: espeye
  name: esp-eye
  external_clock:
    pin: GPIO4
    frequency: 20MHz
  i2c_pins:
    sda: GPIO18
    scl: GPIO23
  data_pins: [GPIO34, GPIO13, GPIO14, GPIO35, GPIO39, GPIO38, GPIO37, GPIO36]
  vsync_pin: GPIO5
  href_pin: GPIO27
  pixel_clock_pin: GPIO25
  resolution: 640X480
  jpeg_quality: 10  # max. 63
  max_framerate: 5.0fps
  idle_framerate: 0.2fps
  vertical_flip: true
  horizontal_mirror: false
 #... deleted for brevity
  test_pattern: True

esp32_camera_web_server:
  - port: 8080
    mode: stream
  - port: 8081
    mode: snapshot

And an ESP32 using an ili9xxx e-paper display on which I’d like to see a snapshot from the camera. This is the relevant yaml:

display:
  - platform: waveshare_epaper
    id: epaperdisplay
    busy_pin:  GPIO39 #BUSY
    reset_pin: GPIO37 #RST
    dc_pin:    GPIO35 #DC
    cs_pin:    GPIO33 #CS
    model: 4.20in-v2
    update_interval: 60s
    reset_duration: 2ms
    rotation: 0
    lambda: |-
      it.image(20, 200, id(mdi_alert));  //This works
      it.image(120,200, id(lpg_level));  //But not this....

http_request:
  verify_ssl: false

online_image:
  - url: http://192.168.0.21:8081
    format: png
    id: lpg_level
    resize: 80x80
    update_interval: 10s #Can't wait. Increase later...
    on_download_finished:
      then:
        - component.update: epaperdisplay

With this setup, the logging shows this:

[20:50:57][I][online_image:103]: Updating image
[20:50:58][D][http_request.arduino:124]: Content-Length: 13687
[20:50:58][D][online_image:128]: Starting download
[20:50:58][I][online_image:144]: Downloading image
[20:50:58][E][online_image.png:058]: Error decoding image: Incorrect PNG signature
[20:50:58][E][online_image:172]: Error when decoding image.

I guess that my problem is that the online_image: requires a png format but the camera server is generating jpeg? How / Where can I convert?

Regards, Martin

Have you tried setting format: jpg? This is an absolute shot in the dark, since the documentation only mentions png as an option, and I haven’t used this component myself yet.

Otherwise, can you see if it’s possible to set the filename of the snapshot to something.png? (The documentation mentions this as an option, so maybe it works)

If you mean in online_image:? Then no, that does not work.

Yes, I have been able to test saving a snapshot as a PNG, using Developer Tools | Actions:

action: camera.snapshot
target:
  device_id: 9a7f5e1fa1518cc9bc1c8de158ea7014
data:
  filename: /config/www/image.png

SO… That leads on to: How do I get ESP-EYE code (listed at head of this posting) to do the same? And where should it be saved?
This is a never ending rabbit hole…
Many thanks, M.

Additionally…
It seems that although I am saving the snapshot with the extension .PNG, it remains a .JPG image!

Oh I went a bit faster there than I realised. I thought the snapshot action would also change the camera itself.

What you can do, is, a bit more complicated.
You’ll need to add a generic camera: Generic Camera - Home Assistant
And after taking the snapshot, use the following service:

service: local_file.update_file_path
data:
  entity_id: camera.generic_camera
  file_path: /new_snapshot.png

I believe the static_url should then change to the new image? It may also be the snapshot should change by itself when you safe the snapshot under the same name, but I’m not sure. I’ve used the generic camera for other things.

Regarding the actual type not changing: maybe the ESP can still figure it out? (Tbh my hopes are low). Otherwise, all I can think of is using Pyscript with the PIL Image package, and using that to actually save the file as a png.