Skip to content

Instantly share code, notes, and snippets.

@xximjasonxx
Created September 2, 2019 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xximjasonxx/8eeeee18f20d276f1c977d5d7ab99538 to your computer and use it in GitHub Desktop.
Save xximjasonxx/8eeeee18f20d276f1c977d5d7ab99538 to your computer and use it in GitHub Desktop.
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