TechnikTobi / little_exif

A little library for reading and writing EXIF data in pure Rust.
Apache License 2.0
18 stars 4 forks source link

Provide exif data for img_parts #2

Open floric opened 5 months ago

floric commented 5 months ago

Hey :)

would it be possible to get the exif data as raw bytes instead of writing to an image? The background is, that I'm writing an image directly to an output stream without any filesystem. So I like to build the exif data, add this to the image with img_parts and render the result directly in a HTTP response.

And: would this exif payload be generic or is it already prepared for the output format (eg. jpeg or png)?

What do you think?

Kind regards, Florian

TechnikTobi commented 5 months ago

Hi,

getting the EXIF data itself as "raw bytes" (I assume a Vec should be fine?) can be added relatively easily. However, writing this to an output stream can be a bit tricky:

To conclude: Yes, getting the EXIF data itself (and performing at least some of the file-specific encoding) should be possible via little_exif after a small update. However, the other file-type specific stuff you'll have to figure out yourself.

Best, Tobi

floric commented 5 months ago

Hi,

getting the EXIF data itself as "raw bytes" (I assume a Vec should be fine?) can be added relatively easily. However, writing this to an output stream can be a bit tricky:

* As you mentioned, what you have to write to the stream depends on the filetype, e.g. PNG has a special header, needs additional PNG-specific encoding, etc. (sidenote: PNG is, of the currently supported file types, the _worst_ to work with from a programmer's perspective)

* You also have to figure out _where_ (or in case of a stream, _when_) to write the EXIF data

* With some file types (e.g. WebP) you need to have the encoded EXIF data _before_ you start your output stream as you need to know the size of the resulting file to write it at the start.

To conclude: Yes, getting the EXIF data itself (and performing at least some of the file-specific encoding) should be possible via little_exif after a small update. However, the other file-type specific stuff you'll have to figure out yourself.

Best, Tobi

Hey Tobi,

thanks a lot for this comprehensive and fast response. I hope, that using img_pars::ImageEXIF will be enough. At least there I can provide bytes (Vec<u8>) for EXIF data as well as ICC profiles. The exporting to the different formats is done with the resulting object. I could give it a try, if providing the EXIF data as bytes is really easy for you, and see if img_parts really handles all of the hard work mentioned by you for us.

TechnikTobi commented 5 months ago

Hi,

I've added a new function for the Metadata called as_u8_vec where you provide information about which image format you want to use (e.g. FileExtension::WEBP) and get the EXIF data as a Vec<u8>. However, as always, the PNG format is a pita to work with, so don't expect this to work on the first try. I'd be glad to help you with getting this to run with img_parts and PNGs if required, but there is the chance that this library will need an update as well due to how EXIF data is handled over there.

So, try it out with little_exif ver 0.3.0 and let me know what you think and if it works or where work is still required. And, in the likely case that you do run into problems, it would be great to get some sort of file stream as hex code or (best case) an image file you tried to create but are unable to use due to problems with the EXIF data so I can compare and debug.

Best, Tobi

floric commented 5 months ago

Hi,

I've added a new function for the Metadata called as_u8_vec where you provide information about which image format you want to use (e.g. FileExtension::WEBP) and get the EXIF data as a Vec<u8>. However, as always, the PNG format is a pita to work with, so don't expect this to work on the first try. I'd be glad to help you with getting this to run with img_parts and PNGs if required, but there is the chance that this library will need an update as well due to how EXIF data is handled over there.

So, try it out with little_exif ver 0.3.0 and let me know what you think and if it works or where work is still required. And, in the likely case that you do run into problems, it would be great to get some sort of file stream as hex code or (best case) an image file you tried to create but are unable to use due to problems with the EXIF data so I can compare and debug.

Best, Tobi

Hey :) thanks a lot. I will definitely give it a try. In the mean time I was also successful to use kamadak/exif-rs for the same purpose. But I only tried JPEG so far. But your lib is a little easier to write and read.

h3x4d3c1m4l commented 4 months ago

This works for me:

https://github.com/h3x4d3c1m4l/momento-booth/pull/353/files#diff-01e8fa73909b86c309b9e31ac7ca842cadabf5e374ff06f1a4fe0b43822b6de8R16-R27

Note that you need to strip the first 10 bytes of the little_exif output (see line 25). Took me a while to find out 😄 !