Merge branch 'netcore/feature/imagesharp-config' into netcore/feature/aspnetcore-config
This commit is contained in:
@@ -2,37 +2,70 @@
|
||||
<processing preserveExifMetaData="true" fixGamma="false" interceptAllRequests="false" allowCacheBuster="true">
|
||||
|
||||
|
||||
<plugins>
|
||||
<plugin name="Gamma" type="ImageProcessor.Web.Processors.Gamma, ImageProcessor.Web" />
|
||||
<plugins>
|
||||
<plugin name="Gamma" type="ImageProcessor.Web.Processors.Gamma, ImageProcessor.Web"/>
|
||||
|
||||
<plugin name="Alpha" type="ImageProcessor.Web.Processors.Alpha, ImageProcessor.Web" /><plugin name="AutoRotate" type="ImageProcessor.Web.Processors.AutoRotate, ImageProcessor.Web" enabled="true" /><plugin name="Background" type="ImageProcessor.Web.Processors.Background, ImageProcessor.Web">
|
||||
<settings>
|
||||
<setting key="VirtualPath" value="~/images/imageprocessor/background/" />
|
||||
</settings>
|
||||
</plugin><plugin name="BackgroundColor" type="ImageProcessor.Web.Processors.BackgroundColor, ImageProcessor.Web" enabled="true" /><plugin name="Brightness" type="ImageProcessor.Web.Processors.Brightness, ImageProcessor.Web" /><plugin name="Contrast" type="ImageProcessor.Web.Processors.Contrast, ImageProcessor.Web" /><plugin name="Crop" type="ImageProcessor.Web.Processors.Crop, ImageProcessor.Web" enabled="true" /><plugin name="DetectEdges" type="ImageProcessor.Web.Processors.DetectEdges, ImageProcessor.Web" /><plugin name="EntropyCrop" type="ImageProcessor.Web.Processors.EntropyCrop, ImageProcessor.Web" /><plugin name="Filter" type="ImageProcessor.Web.Processors.Filter, ImageProcessor.Web" /><plugin name="Flip" type="ImageProcessor.Web.Processors.Flip, ImageProcessor.Web" /><plugin name="Format" type="ImageProcessor.Web.Processors.Format, ImageProcessor.Web" enabled="true" /><plugin name="GaussianBlur" type="ImageProcessor.Web.Processors.GaussianBlur, ImageProcessor.Web">
|
||||
<settings>
|
||||
<setting key="MaxSize" value="22" />
|
||||
<setting key="MaxSigma" value="5.1" />
|
||||
<setting key="MaxThreshold" value="100" />
|
||||
</settings>
|
||||
</plugin><plugin name="GaussianSharpen" type="ImageProcessor.Web.Processors.GaussianSharpen, ImageProcessor.Web">
|
||||
<settings>
|
||||
<setting key="MaxSize" value="22" />
|
||||
<setting key="MaxSigma" value="5.1" />
|
||||
<setting key="MaxThreshold" value="100" />
|
||||
</settings>
|
||||
</plugin><plugin name="Halftone" type="ImageProcessor.Web.Processors.Halftone, ImageProcessor.Web" /><plugin name="Hue" type="ImageProcessor.Web.Processors.Hue, ImageProcessor.Web" /><plugin name="Mask" type="ImageProcessor.Web.Processors.Mask, ImageProcessor.Web">
|
||||
<settings>
|
||||
<setting key="VirtualPath" value="~/images/imageprocessor/mask/" />
|
||||
</settings>
|
||||
</plugin><plugin name="Meta" type="ImageProcessor.Web.Processors.Meta, ImageProcessor.Web" /><plugin name="Overlay" type="ImageProcessor.Web.Processors.Overlay, ImageProcessor.Web">
|
||||
<settings>
|
||||
<setting key="VirtualPath" value="~/images/imageprocessor/overlay/" />
|
||||
</settings>
|
||||
</plugin><plugin name="Pixelate" type="ImageProcessor.Web.Processors.Pixelate, ImageProcessor.Web" /><plugin name="Quality" type="ImageProcessor.Web.Processors.Quality, ImageProcessor.Web" enabled="true" /><plugin name="ReplaceColor" type="ImageProcessor.Web.Processors.ReplaceColor, ImageProcessor.Web" /><plugin name="Resize" type="ImageProcessor.Web.Processors.Resize, ImageProcessor.Web" enabled="true">
|
||||
<settings>
|
||||
<setting key="MaxWidth" value="5000" />
|
||||
<setting key="MaxHeight" value="5000" />
|
||||
</settings>
|
||||
</plugin><plugin name="Rotate" type="ImageProcessor.Web.Processors.Rotate, ImageProcessor.Web" /><plugin name="RotateBounded" type="ImageProcessor.Web.Processors.RotateBounded, ImageProcessor.Web" /><plugin name="RoundedCorners" type="ImageProcessor.Web.Processors.RoundedCorners, ImageProcessor.Web" /><plugin name="Saturation" type="ImageProcessor.Web.Processors.Saturation, ImageProcessor.Web" /><plugin name="Tint" type="ImageProcessor.Web.Processors.Tint, ImageProcessor.Web" /><plugin name="Vignette" type="ImageProcessor.Web.Processors.Vignette, ImageProcessor.Web" /><plugin name="Watermark" type="ImageProcessor.Web.Processors.Watermark, ImageProcessor.Web" /></plugins><presets>
|
||||
</presets></processing>
|
||||
<plugin name="Alpha" type="ImageProcessor.Web.Processors.Alpha, ImageProcessor.Web"/>
|
||||
<plugin name="AutoRotate" type="ImageProcessor.Web.Processors.AutoRotate, ImageProcessor.Web" enabled="true"/>
|
||||
<plugin name="Background" type="ImageProcessor.Web.Processors.Background, ImageProcessor.Web">
|
||||
<settings>
|
||||
<setting key="VirtualPath" value="~/images/imageprocessor/background/"/>
|
||||
</settings>
|
||||
</plugin>
|
||||
<plugin name="BackgroundColor" type="ImageProcessor.Web.Processors.BackgroundColor, ImageProcessor.Web"
|
||||
enabled="true"/>
|
||||
<plugin name="Brightness" type="ImageProcessor.Web.Processors.Brightness, ImageProcessor.Web"/>
|
||||
<plugin name="Contrast" type="ImageProcessor.Web.Processors.Contrast, ImageProcessor.Web"/>
|
||||
<plugin name="Crop" type="ImageProcessor.Web.Processors.Crop, ImageProcessor.Web" enabled="true"/>
|
||||
<plugin name="DetectEdges" type="ImageProcessor.Web.Processors.DetectEdges, ImageProcessor.Web"/>
|
||||
<plugin name="EntropyCrop" type="ImageProcessor.Web.Processors.EntropyCrop, ImageProcessor.Web"/>
|
||||
<plugin name="Filter" type="ImageProcessor.Web.Processors.Filter, ImageProcessor.Web"/>
|
||||
<plugin name="Flip" type="ImageProcessor.Web.Processors.Flip, ImageProcessor.Web"/>
|
||||
<plugin name="Format" type="ImageProcessor.Web.Processors.Format, ImageProcessor.Web" enabled="true"/>
|
||||
<plugin name="GaussianBlur" type="ImageProcessor.Web.Processors.GaussianBlur, ImageProcessor.Web">
|
||||
<settings>
|
||||
<setting key="MaxSize" value="22"/>
|
||||
<setting key="MaxSigma" value="5.1"/>
|
||||
<setting key="MaxThreshold" value="100"/>
|
||||
</settings>
|
||||
</plugin>
|
||||
<plugin name="GaussianSharpen" type="ImageProcessor.Web.Processors.GaussianSharpen, ImageProcessor.Web">
|
||||
<settings>
|
||||
<setting key="MaxSize" value="22"/>
|
||||
<setting key="MaxSigma" value="5.1"/>
|
||||
<setting key="MaxThreshold" value="100"/>
|
||||
</settings>
|
||||
</plugin>
|
||||
<plugin name="Halftone" type="ImageProcessor.Web.Processors.Halftone, ImageProcessor.Web"/>
|
||||
<plugin name="Hue" type="ImageProcessor.Web.Processors.Hue, ImageProcessor.Web"/>
|
||||
<plugin name="Mask" type="ImageProcessor.Web.Processors.Mask, ImageProcessor.Web">
|
||||
<settings>
|
||||
<setting key="VirtualPath" value="~/images/imageprocessor/mask/"/>
|
||||
</settings>
|
||||
</plugin>
|
||||
<plugin name="Meta" type="ImageProcessor.Web.Processors.Meta, ImageProcessor.Web"/>
|
||||
<plugin name="Overlay" type="ImageProcessor.Web.Processors.Overlay, ImageProcessor.Web">
|
||||
<settings>
|
||||
<setting key="VirtualPath" value="~/images/imageprocessor/overlay/"/>
|
||||
</settings>
|
||||
</plugin>
|
||||
<plugin name="Pixelate" type="ImageProcessor.Web.Processors.Pixelate, ImageProcessor.Web"/>
|
||||
<plugin name="Quality" type="ImageProcessor.Web.Processors.Quality, ImageProcessor.Web" enabled="true"/>
|
||||
<plugin name="ReplaceColor" type="ImageProcessor.Web.Processors.ReplaceColor, ImageProcessor.Web"/>
|
||||
<plugin name="Resize" type="ImageProcessor.Web.Processors.Resize, ImageProcessor.Web" enabled="true">
|
||||
<settings>
|
||||
<setting key="MaxWidth" value="5000"/>
|
||||
<setting key="MaxHeight" value="5000"/>
|
||||
</settings>
|
||||
</plugin>
|
||||
<plugin name="Rotate" type="ImageProcessor.Web.Processors.Rotate, ImageProcessor.Web"/>
|
||||
<plugin name="RotateBounded" type="ImageProcessor.Web.Processors.RotateBounded, ImageProcessor.Web"/>
|
||||
<plugin name="RoundedCorners" type="ImageProcessor.Web.Processors.RoundedCorners, ImageProcessor.Web"/>
|
||||
<plugin name="Saturation" type="ImageProcessor.Web.Processors.Saturation, ImageProcessor.Web"/>
|
||||
<plugin name="Tint" type="ImageProcessor.Web.Processors.Tint, ImageProcessor.Web"/>
|
||||
<plugin name="Vignette" type="ImageProcessor.Web.Processors.Vignette, ImageProcessor.Web"/>
|
||||
<plugin name="Watermark" type="ImageProcessor.Web.Processors.Watermark, ImageProcessor.Web"/>
|
||||
</plugins>
|
||||
<presets>
|
||||
</presets>
|
||||
</processing>
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using SixLabors.ImageSharp.Web;
|
||||
using SixLabors.ImageSharp.Web.Caching;
|
||||
using SixLabors.ImageSharp.Web.Commands;
|
||||
using SixLabors.ImageSharp.Web.DependencyInjection;
|
||||
using SixLabors.ImageSharp.Web.Middleware;
|
||||
using SixLabors.ImageSharp.Web.Processors;
|
||||
using SixLabors.ImageSharp.Web.Providers;
|
||||
using SixLabors.Memory;
|
||||
|
||||
namespace Umbraco.Web.Website.AspNetCore
|
||||
{
|
||||
@@ -7,11 +17,58 @@ namespace Umbraco.Web.Website.AspNetCore
|
||||
{
|
||||
public static IServiceCollection AddUmbracoWebsite(this IServiceCollection services)
|
||||
{
|
||||
services.AddImageSharp();
|
||||
|
||||
services.AddUmbracoImageSharp();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddUmbracoImageSharp(this IServiceCollection services)
|
||||
{
|
||||
services.AddImageSharpCore(
|
||||
options =>
|
||||
{
|
||||
options.Configuration = SixLabors.ImageSharp.Configuration.Default;
|
||||
options.MaxBrowserCacheDays = 7;
|
||||
options.MaxCacheDays = 365;
|
||||
options.CachedNameLength = 8;
|
||||
options.OnParseCommands = context =>
|
||||
{
|
||||
RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Width, 5000);
|
||||
RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Height, 5000);
|
||||
};
|
||||
options.OnBeforeSave = _ => { };
|
||||
options.OnProcessed = _ => { };
|
||||
options.OnPrepareResponse = _ => { };
|
||||
})
|
||||
.SetRequestParser<QueryCollectionRequestParser>()
|
||||
.SetMemoryAllocator(provider => ArrayPoolMemoryAllocator.CreateWithMinimalPooling())
|
||||
.Configure<PhysicalFileSystemCacheOptions>(options =>
|
||||
{
|
||||
options.CacheFolder = "../app_data/cache";
|
||||
})
|
||||
.SetCache<PhysicalFileSystemCache>()
|
||||
.SetCacheHash<CacheHash>()
|
||||
.AddProvider<PhysicalFileSystemProvider>()
|
||||
.AddProcessor<ResizeWebProcessor>()
|
||||
.AddProcessor<FormatWebProcessor>()
|
||||
.AddProcessor<BackgroundColorWebProcessor>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
private static void RemoveIntParamenterIfValueGreatherThen(IDictionary<string, string> commands, string parameter, int maxValue)
|
||||
{
|
||||
if (commands.TryGetValue(parameter, out var command))
|
||||
{
|
||||
if (int.TryParse(command, out var i))
|
||||
{
|
||||
if (i > maxValue)
|
||||
{
|
||||
commands.Remove(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user