imazen / imageflow-dotnet

The official .NET API for Imageflow, the Rust image processing and optimization engine for web servers
GNU Affero General Public License v3.0
143 stars 25 forks source link

Unable to read WEBP images using ImageFlow.Net #16

Closed thecaptncode closed 4 years ago

thecaptncode commented 4 years ago

I have installed ImageFlow.Net and the correct runtimes into my asp.net webforms project. ImageFlow reads JPG and other image formats just fine using the following code:

ImageInfo info = ImageJob.GetImageInfo(new StreamSource(msDoc, false)).Result;
int width = (int)info.ImageWidth;
int height = (int)info.ImageHeight;
string ext = info.PreferredExtension;

However, when I use GetImageInfo on a WEBP image I receive the following exception:

Imageflow.Bindings.ImageflowException: ImageMalformed: NoEnabledDecoderFound: No ENABLED decoder found for file starting in [49, 49, BC, 1, 20, 0, 0, 0, 24, C3, DD, 6F] at
imageflow_core\src\codecs\mod.rs:153:20
https://github.com/imazen/imageflow/blob/1a7e1eecd8f04cab4413b48c2bf8bd5bbf140f5d/imageflow_core\src\codecs\mod.rs#L153
imageflow_core\src\context.rs:133:103
https://github.com/imazen/imageflow/blob/1a7e1eecd8f04cab4413b48c2bf8bd5bbf140f5d/imageflow_core\src\context.rs#L133
imageflow_core\src\context.rs:174:66
https://github.com/imazen/imageflow/blob/1a7e1eecd8f04cab4413b48c2bf8bd5bbf140f5d/imageflow_core\src\context.rs#L174
imageflow_abi\src\lib.rs:707:62
https://github.com/imazen/imageflow/blob/1a7e1eecd8f04cab4413b48c2bf8bd5bbf140f5d/imageflow_abi\src\lib.rs#L707

Is there something I didn't install or need to reference? An example image that throws the above exceptions with the above code is here: https://media.wuerth.com/source/eshop/stmedia/wuerth/images/std.lang.all/resolutions/category/576px/105488.jpg

imazen-bot commented 4 years ago

According to the error message the file does not start with a valid image header.

The code that checks these can be found here: https://github.com/imazen/imageflow/blob/696fea2036d3439dd6969570caef9b87cbc76db9/imageflow_core/src/codecs/mod.rs#L77-L88

lilith commented 4 years ago

Do you have an example image in webp format that causes this error? Are you sure that nothing else is seeking the stream before it is read?

thecaptncode commented 4 years ago

There is a link at the bottom of the issue to an image that produces exactly that error. Examining the image in Firefox reveals that it is a WEBP image.

I am certain the stream is at the beginning. I can pick through the stream to see if it looks as expected. Perhaps there is an issue there. I have examined the WEBP file before in a hex editor and I saw the RIFF and WEBP in it where expected but I did not check the stream to see if that was it.

lilith commented 4 years ago

The error message gives you the first bytes of the stream, in this case [49, 49, BC, 1, 20, 0, 0, 0, 24, C3, DD, 6F]. That does not look like a RIFF/WEBP header. Can you share all of the code you are using to load the stream? I would suggest debugging and inspecting the stream bytes.

thecaptncode commented 4 years ago

That was a very good catch. I debugged the stream and found an encoding issue that was only manifesting when I was testing WEBP. I am sorry to bother you. Sometimes the ones that stump you are due to making an assumption. Thank you for pointing that out.