Skip to content

sebastienros/ImageSharp.Web

 
 

Repository files navigation

SixLabors.ImageSharp.Web
SixLabors.ImageSharp.Web

GitHub license GitHub issues GitHub stars GitHub forks Gitter

Twitter OpenCollective OpenCollective

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 Build Status
Windows Build status

Installation

Install stable releases via Nuget; development releases are available via MyGet.

Package Name Release (NuGet) Nightly (MyGet)
SixLabors.ImageSharp.Web NuGet MyGet

Packages

  • 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.OnValidate = _ => { };
            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>()
        .SetCache<PhysicalFileSystemCache>()
        .SetCacheHash<CacheHash>()
        .SetAsyncKeyLock<AsyncKeyLock>()
        .AddResolver<PhysicalFileSystemResolver>()
        .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.OnValidate = _ => { };
            options.OnBeforeSave = _ => { };
            options.OnProcessed = _ => { };
            options.OnPrepareResponse = _ => { };
        })
    .SetRequestParser<QueryCollectionRequestParser>()
    .SetBufferManager<PooledBufferManager>()
    .SetCache(provider =>
      {
          var p = new PhysicalFileSystemCache(
              provider.GetRequiredService<IHostingEnvironment>(),
              provider.GetRequiredService<IBufferManager>(),
              provider.GetRequiredService<IOptions<ImageSharpMiddlewareOptions>>());

          p.Settings[PhysicalFileSystemCache.Folder] = PhysicalFileSystemCache.DefaultCacheFolder;
          p.Settings[PhysicalFileSystemCache.CheckSourceChanged] = "true";

          return p;
      })
    .SetCacheHash<CacheHash>()
    .SetAsyncKeyLock<AsyncKeyLock>()
    .AddResolver<PhysicalFileSystemResolver>()
    .AddProcessor<ResizeWebProcessor>()
    .AddProcessor<FormatWebProcessor>()
    .AddProcessor<BackgroundColorWebProcessor>();

Manual build

If you prefer, you can compile ImageSharp.Web yourself (please do and help!), you'll need:

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

How can you help?

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.

The ImageSharp.Web Team

Grand High Eternal Dictator

Core Team

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]

About

☁️ Middleware for ASP.NET-Core for image manipulation.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 97.7%
  • PowerShell 1.8%
  • Batchfile 0.5%