• Articles
  • API Documentation
Search Results for

    Show / Hide Table of Contents
    • ImageSharp
      • Getting Started
        • Pixel Formats
        • Image Formats
        • Processing Images
          • Resizing Images
        • Working with Pixel Buffers
        • Configuration
        • Memory Management
    • ImageSharp.Drawing
      • Getting Started
    • ImageSharp.Web
      • Getting Started
        • Processing Commands
        • Image Providers
        • Image Caches
    • Fonts
      • Getting Started
      • Custom Rendering

    Getting Started

    Note

    The official guide assumes intermediate level knowledge of C# and .NET. If you are totally new to .NET development, it might not be the best idea to jump right into a framework as your first step - grasp the basics then come back. Prior experience with other languages and frameworks helps, but is not required.

    Setup and Configuration

    Once installed you will need to add the following code to ConfigureServices and Configure in your Startup.cs file.

    This installs the the default service and options.

    public void ConfigureServices(IServiceCollection services) {
        // Add the default service and options.
        services.AddImageSharp();
    }
    
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
    
        // Add the image processing middleware.
        app.UseImageSharp();
    }
    

    The fluent configuration is flexible allowing you to configure a multitude of different options. For example you can 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
                // All properties have been listed for demonstration purposes
                // only.
                options.Configuration = Configuration.Default;
                options.MemoryStreamManager = new RecyclableMemoryStreamManager();
                options.BrowserMaxAge = TimeSpan.FromDays(7);
                options.CacheMaxAge = TimeSpan.FromDays(365);
                options.CachedNameLength = 8;
                options.OnParseCommandsAsync = _ => Task.CompletedTask;
                options.OnBeforeSaveAsync = _ => Task.CompletedTask;
                options.OnProcessedAsync = _ => Task.CompletedTask;
                options.OnPrepareResponseAsync = _ => Task.CompletedTask;
            });
    

    Or you can fine-grain control adding the default options and configure other services.

    // Fine-grain control adding the default options and configure other services.
    services.AddImageSharp()
            .RemoveProcessor<FormatWebProcessor>()
            .RemoveProcessor<BackgroundColorWebProcessor>();
    

    There are also factory methods for each builder that will allow building from configuration files.

    // Use the factory methods to configure the PhysicalFileSystemCacheOptions
    services.AddImageSharp()
        .Configure<PhysicalFileSystemCacheOptions>(options =>
        {
            options.CacheFolder = "different-cache";
        });
    

    Full Configuration API options are available here.

    • Improve this Doc
    In This Article
    Back to top Generated by DocFX