add blur web processor; set image cache defaults

This commit is contained in:
2024-04-02 11:46:27 +02:00
parent 2c8d4361d4
commit c759fcb1a7
5 changed files with 60 additions and 91 deletions
@@ -0,0 +1,48 @@
using Microsoft.Extensions.Logging;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Web;
using SixLabors.ImageSharp.Web.Commands;
using SixLabors.ImageSharp.Web.Processors;
using System.Globalization;
namespace zero.Media.ImageSharp.Processors;
public class BlurWebProcessor : IImageWebProcessor
{
// <summary>
/// The command constant for the gaussian blur sigma.
/// </summary>
public const string Blur = "blur";
/// <summary>
/// The reusable collection of commands.
/// </summary>
private static readonly IEnumerable<string> BlurCommands = new[] { Blur };
/// <inheritdoc/>
public IEnumerable<string> Commands { get; } = BlurCommands;
/// <inheritdoc/>
public FormattedImage Process(
FormattedImage image,
ILogger logger,
CommandCollection commands,
CommandParser parser,
CultureInfo culture)
{
if (commands.Contains(Blur))
{
float sigma = parser.ParseValue<float>(commands.GetValueOrDefault(Blur), culture);
if (sigma != 0)
{
image.Image.Mutate(x => x.GaussianBlur(sigma));
}
}
return image;
}
/// <inheritdoc/>
public bool RequiresTrueColorPixelFormat(CommandCollection commands, CommandParser parser, CultureInfo culture) => true;
}
-38
View File
@@ -1,38 +0,0 @@
// using Raven.Client.Documents.Indexes;
//
// namespace zero.Media;
//
// public class Media_ByChildren : ZeroMultiMapIndex<Media_ByChildren.Result>
// {
// public class Result : ZeroIdEntity, ISupportsDbConventions
// {
// public string ParentId { get; set; }
//
// public int ChildrenCount { get; set; }
//
// public string[] ChildrenIds { get; set; }
// }
//
//
// protected override void Create()
// {
// AddMap<Media>(items => items.Select(item => new Result()
// {
// Id = item.Id,
// ParentId = item.ParentId,
// ChildrenCount = 1,
// ChildrenIds = new string[] { }
// }));
//
// Reduce = results => results.GroupBy(x => new { x.ParentId }).Select(group => new Result()
// {
// Id = null,
// ParentId = group.Key.ParentId,
// ChildrenCount = group.Sum(x => x.ChildrenCount),
// ChildrenIds = group.Select(x => x.Id).ToArray()
// });
//
// StoreAllFields(FieldStorage.Yes);
// Index(x => x.ParentId, FieldIndexing.Exact);
// }
// }
-45
View File
@@ -1,45 +0,0 @@
// using Raven.Client.Documents.Indexes;
//
// namespace zero.Media;
//
// public class Media_ByHierarchy : ZeroIndex<Media, Media_ByHierarchy.Result>
// {
// public class Result : ZeroIdEntity, ISupportsDbConventions
// {
// public string Name { get; set; }
//
// public List<PathResult> Path { get; set; } = new List<PathResult>();
//
// public string[] PathIds { get; set; } = Array.Empty<string>();
// }
//
//
// public class PathResult
// {
// public string Id { get; set; }
//
// public string Name { get; set; }
// }
//
//
// protected override void Create()
// {
// Map = items => items
// .Select(item => new
// {
// Item = item,
// Path = Recurse(item, x => LoadDocument<Media>(x.ParentId)).Where(x => x != null && x.Id != null && x.Id != item.Id).Reverse()
// })
// .Select(item => new Result
// {
// Id = item.Item.Id,
// Name = item.Item.Name,
// Path = item.Path.Select(current => new PathResult() { Id = current.Id, Name = current.Name }).ToList(),
// PathIds = item.Path.Select(current => current.Id).ToArray()
// });
//
// StoreAllFields(FieldStorage.Yes);
// Index("PathIds", FieldIndexing.Exact);
// //Index(x => x.ChannelId, FieldIndexing.Exact);
// }
// }
+1 -1
View File
@@ -5,7 +5,7 @@ namespace zero.Media;
public class MediaOptions
{
public string FolderPath { get; set; }
public string FolderPath { get; set; } = string.Empty;
public string PublicPathPrefix { get; set; } = string.Empty;
+11 -7
View File
@@ -1,15 +1,13 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using SixLabors.ImageSharp.Processing;
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using SixLabors.ImageSharp.Web.Caching;
using SixLabors.ImageSharp.Web.DependencyInjection;
using System.IO;
using zero.Media.ImageSharp;
using zero.Numbers;
using zero.Media.ImageSharp.Processors;
namespace zero.Media;
@@ -24,7 +22,13 @@ internal class ZeroMediaModule : ZeroModule
.AddProvider<PhysicalFileProvider>()
.AddProcessor<RotateWebProcessor>()
.AddProcessor<StripMetadataWebProcessor>()
.Configure<PhysicalFileSystemCacheOptions>(configuration.GetSection("Zero:Media:ImageSharp:Cache"));
.AddProcessor<BlurWebProcessor>();
services.AddOptions<PhysicalFileSystemCacheOptions>().Configure(opts =>
{
opts.CacheRootPath = "~/";
opts.CacheFolder = "cache";
}).Bind(configuration.GetSection("Zero:Media:ImageSharp:Cache"));
//configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "Config/imaging.json"), true, true);
//configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), $"Config/imaging.{builder.Environment.EnvironmentName}.json"), true);