EncoderInfo not set correctly if output to Stream
Closed this issue · 0 comments
nquandt commented
Given some image.. and EncoderOptions set to Webp type.. The output stream is not encoded correctly unless I manually call TrySetEncoderFormat.. (where I was under the impression this should be set based on the EncoderOptions)
var newStream = new MemoryStream();
var settings = new ProcessImageSettings()
{
EncoderOptions = new WebpLossyEncoderOptions(80),
};
MagicImageProcessor.ProcessImage("./image.webp", newStream, settings); // load an image however..
var bytes1 = newStream.ToArray();
var newStream2 = new MemoryStream();
var settings = new ProcessImageSettings()
{
EncoderOptions = new WebpLossyEncoderOptions(80),
};
settings.TrySetEncoderFormat("image/webp"); // this line makes it different
MagicImageProcessor.ProcessImage("./image.webp", newStream2 , settings); // load an image however..
var bytes2 = newStream2.ToArray();
Assert.Equal(bytes1.Length, bytes2.Length); // returns false (should be true)
If I output to a file path instead of a stream it sets the encoder correctly (i believe because of this line)
ctx.Settings.EncoderInfo ??= getEncoderFromPath(outPath);