saucecontrol / PhotoSauce

MagicScaler high-performance, high-quality image processing pipeline for .NET
http://photosauce.net/
MIT License
589 stars 49 forks source link

System.Runtime.InteropServices.COMException at PhotoSauce.MagicScaler.WicPlanarCache.loadBuffer #116

Closed leventefabry-mof closed 1 year ago

leventefabry-mof commented 1 year ago

Hey, it happens randomly and with any kind of image. The problem is that I couldn't reproduce it locally just in the server where this Azure function runs. The message is the following: The image is unrecognized. (0x88982F60) PhotoSauce.MagicScaler.WicPlanarCache.loadBuffer

I get an image byte array which I convert to stream and use in the BuildPipeline method.

            if (query.FileFormat == RequestFileFormat.Webp)
            {
                CodecManager.Configure(codecs => { codecs.UseLibwebp(); });
                settings.TrySetEncoderFormat(ImageMimeTypes.Webp);
            }

            using var outputStream = new MemoryStream();
            await Task.Run(() =>
            {
                Stream stream = new MemoryStream(bytes);
                using var pipeline = MagicImageProcessor.BuildPipeline(stream, settings);

                if (query.Blur.HasValue)
                {
                    pipeline.AddTransform(new GaussianBlurTransform(radius: query.Blur.Value)); 
                }

                pipeline.WriteOutput(outputStream);
                pipeline.Dispose();
            });

            var imageBytes = outputStream.ToArray();
            await outputStream.DisposeAsync();

Do you have any idea what can be the problem? Thanks in advance for your help!