SolderedElectronics / Inkplate-Arduino-library

Inkplate family Arduino library. The easiest way to add e-paper to your project.
https://inkplate.readthedocs.io/en/latest/arduino.html
GNU Lesser General Public License v3.0
245 stars 80 forks source link

Feature request: Auto-detect image format #258

Open jallbrit opened 1 month ago

jallbrit commented 1 month ago

First off, thank you for this library, I have had a lot of fun with my Inkplate 6COLOR. It's very cool and this library makes it really easy to work with.

In the inkplate.drawImage() docs, it says:

Can draw all kinds of images, but they should have a file extensions in them.

But, I'm serving images at an API URL that directly returns an image, so I can't edit the extension... there is no file extension for the API endpoint that my inkplate is reaching out to. And I'm returning random images, so I don't know in advance what type of image it will be (I have a mixture of JPG and PNG).

It would be really great if inkplate.drawImage() could auto-detect whether a given image file is PNG, JPG, or BMP without needing a file extension. I know the different images types have certain headers that could be read.

jallbrit commented 1 month ago

Well, I ended up solving this issue by just fixing my API endpoint to convert to PNG before returning an image, so Inkplate can always expect a PNG. But, I'll leave this issue open for the maintainers to decide what to do.

rsoric commented 1 month ago

Hi @jallbrit,

sorry for a bit a delayed reply on this, I was on PTO.

Glad you're overall enjoying the library :)

drawImage has an overloaded definition which is able to do this kind of format detection: https://github.com/SolderedElectronics/Inkplate-Arduino-library/blob/d33b0e7797eb42fdec34faf164216b547d32cbe3/src/include/Image.cpp#L74C13-L74C22 - and it should work as long as your URL ends in .jpg or .png. Could you try that?

Or do you mean you just have a raw file and we have to look into the actual bytes to see what format it is?

-Rob