ImageSharp.Web is a new high-performance ASP.NET Core middleware leveraging the ImageSharp graphics library.
Pre-release downloads are available from the MyGet package repository.
Build Status | |
---|---|
Linux/Mac | |
Windows |
Install stable releases via Nuget; development releases are available via MyGet.
Package Name | Release (NuGet) | Nightly (MyGet) |
---|---|---|
SixLabors.ImageSharp.Web |
- ImageSharp.Web
- Contains the middleware to integrate a dynamic image manipulation workflow into an ASP.NET Core application.
Once installed you will need to add the following code to ConfigureServices
in your Startup.cs
file.
This installs the the default service and options.
// Add the default service and options.
services.AddImageSharp();
Or add the default service and custom options.
// Add the default service and custom options.
services.AddImageSharp(
options =>
{
// You only need to set the options you want to change here.
options.Configuration = Configuration.Default;
options.MaxBrowserCacheDays = 7;
options.MaxCacheDays = 365;
options.CachedNameLength = 8;
options.OnParseCommands = _ => { };
options.OnBeforeSave = _ => { };
options.OnProcessed = _ => { };
options.OnPrepareResponse = _ => { };
});
Or you can fine-grain control adding the default options and configure all other services.
// Fine-grain control adding the default options and configure all other services. Setting all services is required.
services.AddImageSharpCore()
.SetRequestParser<QueryCollectionRequestParser>()
.SetBufferManager<PooledBufferManager>()
.SetMemoryAllocatorFromMiddlewareOptions()
.SetCacheHash<CacheHash>()
.AddProvider<PhysicalFileSystemProvider>()
.AddProcessor<ResizeWebProcessor>()
.AddProcessor<FormatWebProcessor>()
.AddProcessor<BackgroundColorWebProcessor>();
There are also factory methods for each builder that will allow building from configuration files.
// Use the factory methods to configure the PhysicalFileSystemCache
services.AddImageSharpCore(
options =>
{
options.Configuration = Configuration.Default;
options.MaxBrowserCacheDays = 7;
options.MaxCacheDays = 365;
options.CachedNameLength = 8;
options.OnParseCommands = _ => { };
options.OnBeforeSave = _ => { };
options.OnProcessed = _ => { };
options.OnPrepareResponse = _ => { };
})
.SetRequestParser<QueryCollectionRequestParser>()
.SetMemoryAllocator<ArrayPoolMemoryAllocator>()
.SetCache(provider =>
{
var p = new PhysicalFileSystemCache(
provider.GetRequiredService<IHostingEnvironment>(),
provider.GetRequiredService<IBufferManager>(),
provider.GetRequiredService<IOptions<ImageSharpMiddlewareOptions>>());
p.Settings[PhysicalFileSystemCache.Folder] = PhysicalFileSystemCache.DefaultCacheFolder;
return p;
})
.SetCacheHash<CacheHash>()
.AddProvider<PhysicalFileSystemProvider>()
.AddProcessor<ResizeWebProcessor>()
.AddProcessor<FormatWebProcessor>()
.AddProcessor<BackgroundColorWebProcessor>();
If you prefer, you can compile ImageSharp.Web yourself (please do and help!), you'll need:
- Visual Studio 2017 (or above)
- The .NET Core SDK Installer - Non VSCode link.
Alternatively on Linux you can use:
To clone it locally click the "Clone in Windows" button above or run the following git commands.
git clone https://github.com/SixLabors/ImageSharp.Web
Please... Spread the word, contribute algorithms, submit performance improvements, unit tests, no input is too little. Make sure to read our Contribution Guide before opening a PR.
Grand High Eternal Dictator
Core Team
Support us with a monthly donation and help us continue our activities. [Become a backer]
Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]