Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Stream GetResizedStream(Stream stream, decimal scalingFactor, string mimeType)
{
using (Image<Rgba32> image = Image.Load(stream))
{
var resizeOptions = new ResizeOptions
{
Size = new SixLabors.Primitives.Size
{
Width = Convert.ToInt32(image.Width * scalingFactor),
Height = Convert.ToInt32(image.Height * scalingFactor)
},
Mode = ResizeMode.Stretch
};
image.Mutate(x => x.Resize(resizeOptions));
var memoryStream = new MemoryStream();
image.Save(memoryStream, mimeType.AsEncoder());
return memoryStream;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment