Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot convert from AVIF to BMP #1189

Closed
SebastianStehle opened this issue May 23, 2022 · 7 comments
Closed

Cannot convert from AVIF to BMP #1189

SebastianStehle opened this issue May 23, 2022 · 7 comments

Comments

@SebastianStehle
Copy link

Magick.NET version

11.12

Environment (Operating system, version and so on)

Windows, .NET 6

Description

I have an asset library that supports different formats and stores. I have tests for conversion for all formats, and when I run the test for AVIF -> BMP I have the following behaviors:

  1. The bmp file is way too big. 6MB instead of 1.3MB or so, for a 600x600 image.
  2. When I load the bmp I get the following error: {"length and filesize do not match ' @ error/bmp.c/ReadBMPImage/847"}`

Steps to Reproduce

Checkout: [email protected]:Squidex/assets.git

Run the following test:

image

@dlemstra
Copy link
Owner

Could you reduce this to a small code sample that I can use to reproduce your issue? Otherwise I would need to debug your code.

@SebastianStehle
Copy link
Author

@dlemstra
Copy link
Owner

The problem here is how the image is written. Because you are using the Async method the image is first written to a byte array in memory and then saved to the file to make it possible to do the IO part asynchronous. When you don't use the async method separate files would be created. This is a bug that has to be fixed in Magick.NET but that won't solve your issue because looking at your code it seems that you are using a stream instead of a file. And when you are using a stream each "file"/frame will be written to that output stream sequentially. This is by design but I don't know if anyone even uses that.

In your situation I would advise you to use MagickFormatInfo.Create(MagickFormat) and then use the IsMultiFrame property to determine what you want to do. You should probably use a MagickImage when IsMultiFrame returns false instead of a MagickImageCollection.

@SebastianStehle
Copy link
Author

But it only happens with bmp and in my sample I do not use streams. All other conversions work.

@SebastianStehle
Copy link
Author

Okay, my code was probably wrong. I have changed the saving to this: https://github.com/Squidex/assets/blob/master/Squidex.Assets.ImageMagick/ImageMagickThumbnailGenerator.cs#L125

And this works.

It seems that when I load the avif as collection it has 5 images. No idea, why. And therefore all five images are saved to the bmp stream or file.

dlemstra added a commit that referenced this issue May 25, 2022
@dlemstra
Copy link
Owner

When you load an image with the MagickImageCollection you will get all the layers/frames of the image.

@SebastianStehle
Copy link
Author

Yes. I know. But I created the avif by converting from png manually. So I don't see how it can have more than one 1 layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants