Is there any free and reliable way to compress image files (.jpg/.png) and also create thumbnails in ASP.NET Core 3.1 MVC?
I tried Bitmap’s functions but they throw exceptions like ‘System.Drawing.Common is not supported on this platform’.
Is there any free and reliable way to compress image files (.jpg/.png) and also create thumbnails in ASP.NET Core 3.1 MVC?
I tried Bitmap’s functions but they throw exceptions like ‘System.Drawing.Common is not supported on this platform’.
2
Answers
Yes, there are free and reliable ways to compress image files and create thumbnails in ASP.NET Core without using the System.Drawing.Common library, which is not supported in ASP.NET Core due to platform limitations. Here are two popular and widely used libraries that you can use:
ImageSharp (SixLabors.ImageSharp):
ImageSharp is a cross-platform, high-performance image processing library for .NET that can be used in ASP.NET Core applications. It provides a rich set of features for image manipulation, including resizing, cropping, compression, and more.
To use ImageSharp in your ASP.NET Core 3.1 MVC application, you need to install the SixLabors.ImageSharp.Web NuGet package.
Here’s a sample code snippet to compress an image and generate a thumbnail using ImageSharp: