diff --git a/src/ImageWizard.AWS/AwsExtensions.cs b/src/ImageWizard.AWS/AwsExtensions.cs index 4552ac2..1b6f540 100644 --- a/src/ImageWizard.AWS/AwsExtensions.cs +++ b/src/ImageWizard.AWS/AwsExtensions.cs @@ -4,7 +4,6 @@ using ImageWizard.AWS; using Microsoft.Extensions.DependencyInjection; -using System; namespace ImageWizard; diff --git a/src/ImageWizard.AWS/AwsLoader.cs b/src/ImageWizard.AWS/AwsLoader.cs index 005b6a3..8edc7fe 100644 --- a/src/ImageWizard.AWS/AwsLoader.cs +++ b/src/ImageWizard.AWS/AwsLoader.cs @@ -6,7 +6,6 @@ using Amazon.S3.Model; using ImageWizard.Loaders; using Microsoft.Extensions.Options; -using System.Threading.Tasks; namespace ImageWizard.AWS; diff --git a/src/ImageWizard.Analytics/AnalyticsData.cs b/src/ImageWizard.Analytics/AnalyticsData.cs index 62b82c7..21246c6 100644 --- a/src/ImageWizard.Analytics/AnalyticsData.cs +++ b/src/ImageWizard.Analytics/AnalyticsData.cs @@ -2,8 +2,6 @@ // https://github.com/usercode/ImageWizard // MIT License -using System.Collections.Generic; - namespace ImageWizard.Analytics; /// diff --git a/src/ImageWizard.Analytics/ImageRequestAnalytics.cs b/src/ImageWizard.Analytics/ImageRequestAnalytics.cs index 97da81e..da521a8 100644 --- a/src/ImageWizard.Analytics/ImageRequestAnalytics.cs +++ b/src/ImageWizard.Analytics/ImageRequestAnalytics.cs @@ -2,8 +2,6 @@ // https://github.com/usercode/ImageWizard // MIT License -using System; - namespace ImageWizard.Analytics; /// diff --git a/src/ImageWizard.Azure/AzureBlobExtensions.cs b/src/ImageWizard.Azure/AzureBlobExtensions.cs index 690482f..1bcdb75 100644 --- a/src/ImageWizard.Azure/AzureBlobExtensions.cs +++ b/src/ImageWizard.Azure/AzureBlobExtensions.cs @@ -4,7 +4,6 @@ using ImageWizard.Azure; using Microsoft.Extensions.DependencyInjection; -using System; namespace ImageWizard; diff --git a/src/ImageWizard.Azure/AzureBlobLoader.cs b/src/ImageWizard.Azure/AzureBlobLoader.cs index 9dc1e0a..6d4a87b 100644 --- a/src/ImageWizard.Azure/AzureBlobLoader.cs +++ b/src/ImageWizard.Azure/AzureBlobLoader.cs @@ -7,7 +7,6 @@ using Azure.Storage.Blobs.Models; using ImageWizard.Loaders; using Microsoft.Extensions.Options; -using System.Threading.Tasks; namespace ImageWizard.Azure; diff --git a/src/ImageWizard.DocNET/DocNETPipeline.cs b/src/ImageWizard.DocNET/DocNETPipeline.cs index 59e3ebb..d5798f5 100644 --- a/src/ImageWizard.DocNET/DocNETPipeline.cs +++ b/src/ImageWizard.DocNET/DocNETPipeline.cs @@ -5,9 +5,6 @@ using ImageWizard.DocNET.Filters.Base; using ImageWizard.Processing; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; namespace ImageWizard.DocNET; diff --git a/src/ImageWizard.DocNET/Filters/Base/DocNETFilterContext.cs b/src/ImageWizard.DocNET/Filters/Base/DocNETFilterContext.cs index e005059..1e56d9b 100644 --- a/src/ImageWizard.DocNET/Filters/Base/DocNETFilterContext.cs +++ b/src/ImageWizard.DocNET/Filters/Base/DocNETFilterContext.cs @@ -4,8 +4,6 @@ using ImageWizard.Processing; using ImageWizard.Processing.Results; -using System.IO; -using System.Threading.Tasks; namespace ImageWizard.DocNET.Filters.Base; diff --git a/src/ImageWizard.DocNET/Filters/PageToImageFilter.cs b/src/ImageWizard.DocNET/Filters/PageToImageFilter.cs index d32e0f9..7836427 100644 --- a/src/ImageWizard.DocNET/Filters/PageToImageFilter.cs +++ b/src/ImageWizard.DocNET/Filters/PageToImageFilter.cs @@ -10,7 +10,6 @@ using ImageWizard.Processing.Results; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; -using System.IO; namespace ImageWizard.DocNET.Filters; diff --git a/src/ImageWizard.DocNET/Filters/SubPagesFIlter.cs b/src/ImageWizard.DocNET/Filters/SubPagesFIlter.cs index 1197d11..0b18b7b 100644 --- a/src/ImageWizard.DocNET/Filters/SubPagesFIlter.cs +++ b/src/ImageWizard.DocNET/Filters/SubPagesFIlter.cs @@ -6,7 +6,6 @@ using ImageWizard.Attributes; using ImageWizard.DocNET.Filters.Base; using ImageWizard.Processing.Results; -using System.IO; namespace ImageWizard.DocNET.Filters; diff --git a/src/ImageWizard.DocNET/ImageWizardBuilderExtensions.cs b/src/ImageWizard.DocNET/ImageWizardBuilderExtensions.cs index 7f60061..ceb9067 100644 --- a/src/ImageWizard.DocNET/ImageWizardBuilderExtensions.cs +++ b/src/ImageWizard.DocNET/ImageWizardBuilderExtensions.cs @@ -5,7 +5,6 @@ using ImageWizard.DocNET; using ImageWizard.DocNET.Builder; using ImageWizard.DocNET.Filters; -using System; namespace ImageWizard; diff --git a/src/ImageWizard.FFMpegCore/Builder/FFMpegBuilderExtensions.cs b/src/ImageWizard.FFMpegCore/Builder/FFMpegBuilderExtensions.cs index 8c9ca6c..5bea274 100644 --- a/src/ImageWizard.FFMpegCore/Builder/FFMpegBuilderExtensions.cs +++ b/src/ImageWizard.FFMpegCore/Builder/FFMpegBuilderExtensions.cs @@ -6,7 +6,6 @@ using ImageWizard.FFMpegCore.Builder; using ImageWizard.FFMpegCore.Filters.Base; using Microsoft.Extensions.DependencyInjection; -using System; namespace ImageWizard; diff --git a/src/ImageWizard.FFMpegCore/FFMpegExtensions.cs b/src/ImageWizard.FFMpegCore/FFMpegExtensions.cs index 7c02ba9..f616066 100644 --- a/src/ImageWizard.FFMpegCore/FFMpegExtensions.cs +++ b/src/ImageWizard.FFMpegCore/FFMpegExtensions.cs @@ -5,7 +5,6 @@ using ImageWizard.FFMpegCore; using ImageWizard.FFMpegCore.Builder; using ImageWizard.FFMpegCore.Filters; -using System; namespace ImageWizard; diff --git a/src/ImageWizard.FFMpegCore/FFMpegPipeline.cs b/src/ImageWizard.FFMpegCore/FFMpegPipeline.cs index 7690017..405ec7e 100644 --- a/src/ImageWizard.FFMpegCore/FFMpegPipeline.cs +++ b/src/ImageWizard.FFMpegCore/FFMpegPipeline.cs @@ -5,9 +5,6 @@ using ImageWizard.FFMpegCore.Filters.Base; using ImageWizard.Processing; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; namespace ImageWizard.FFMpegCore; diff --git a/src/ImageWizard.FFMpegCore/Filters/Base/FFMpegContext.cs b/src/ImageWizard.FFMpegCore/Filters/Base/FFMpegContext.cs index 5247f57..069cbb0 100644 --- a/src/ImageWizard.FFMpegCore/Filters/Base/FFMpegContext.cs +++ b/src/ImageWizard.FFMpegCore/Filters/Base/FFMpegContext.cs @@ -4,8 +4,6 @@ using ImageWizard.Processing; using ImageWizard.Processing.Results; -using System; -using System.Threading.Tasks; namespace ImageWizard.FFMpegCore.Filters.Base; diff --git a/src/ImageWizard.FFMpegCore/Filters/FrameFilter.cs b/src/ImageWizard.FFMpegCore/Filters/FrameFilter.cs index 3227b84..9b36581 100644 --- a/src/ImageWizard.FFMpegCore/Filters/FrameFilter.cs +++ b/src/ImageWizard.FFMpegCore/Filters/FrameFilter.cs @@ -8,7 +8,6 @@ using ImageWizard.Attributes; using ImageWizard.FFMpegCore.Filters.Base; using ImageWizard.Processing.Results; -using System.IO; namespace ImageWizard.FFMpegCore.Filters; diff --git a/src/ImageWizard.ImageSharp/Builder/ImageSharpBuilderExtensions.cs b/src/ImageWizard.ImageSharp/Builder/ImageSharpBuilderExtensions.cs index c831433..54b6f2d 100644 --- a/src/ImageWizard.ImageSharp/Builder/ImageSharpBuilderExtensions.cs +++ b/src/ImageWizard.ImageSharp/Builder/ImageSharpBuilderExtensions.cs @@ -11,11 +11,8 @@ namespace ImageWizard; public static class ImageSharpBuilderExtensions { /// - /// Registers an ImageSharp filter. + /// Registers the filter. /// - /// - /// - /// public static IImageSharpBuilder WithFilter(this IImageSharpBuilder builder) where TFilter : ImageSharpFilter { diff --git a/src/ImageWizard.MongoDB/ImageWizard.MongoDB.csproj b/src/ImageWizard.MongoDB/ImageWizard.MongoDB.csproj index d9120bf..f7b82e9 100644 --- a/src/ImageWizard.MongoDB/ImageWizard.MongoDB.csproj +++ b/src/ImageWizard.MongoDB/ImageWizard.MongoDB.csproj @@ -21,8 +21,8 @@ - - + + diff --git a/src/ImageWizard.OpenCvSharp/Filters/Base/OpenCvSharpFilterContext.cs b/src/ImageWizard.OpenCvSharp/Filters/Base/OpenCvSharpFilterContext.cs index bee4555..238d249 100644 --- a/src/ImageWizard.OpenCvSharp/Filters/Base/OpenCvSharpFilterContext.cs +++ b/src/ImageWizard.OpenCvSharp/Filters/Base/OpenCvSharpFilterContext.cs @@ -4,8 +4,6 @@ using ImageWizard.Processing; using ImageWizard.Processing.Results; -using System; -using System.Threading.Tasks; namespace ImageWizard.OpenCvSharp.Filters; diff --git a/src/ImageWizard.OpenCvSharp/OpenCvSharpPipeline.cs b/src/ImageWizard.OpenCvSharp/OpenCvSharpPipeline.cs index 60e8efe..3d327b8 100644 --- a/src/ImageWizard.OpenCvSharp/OpenCvSharpPipeline.cs +++ b/src/ImageWizard.OpenCvSharp/OpenCvSharpPipeline.cs @@ -5,9 +5,6 @@ using ImageWizard.OpenCvSharp.Filters; using ImageWizard.Processing; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; namespace ImageWizard.ImageSharp.Filters; diff --git a/src/ImageWizard.OpenGraph/Loaders/OpenGraphExtensions.cs b/src/ImageWizard.OpenGraph/Loaders/OpenGraphExtensions.cs index 72d02b4..1a02fbc 100644 --- a/src/ImageWizard.OpenGraph/Loaders/OpenGraphExtensions.cs +++ b/src/ImageWizard.OpenGraph/Loaders/OpenGraphExtensions.cs @@ -4,7 +4,6 @@ using ImageWizard.Loaders; using Microsoft.Extensions.DependencyInjection; -using System; namespace ImageWizard; diff --git a/src/ImageWizard.OpenGraph/Loaders/OpenGraphLoader.cs b/src/ImageWizard.OpenGraph/Loaders/OpenGraphLoader.cs index 48eca24..73dac46 100644 --- a/src/ImageWizard.OpenGraph/Loaders/OpenGraphLoader.cs +++ b/src/ImageWizard.OpenGraph/Loaders/OpenGraphLoader.cs @@ -5,9 +5,6 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using OpenGraphNet; -using System; -using System.Net.Http; -using System.Threading.Tasks; namespace ImageWizard.Loaders; diff --git a/src/ImageWizard.OpenGraph/Loaders/OpenGraphOptions.cs b/src/ImageWizard.OpenGraph/Loaders/OpenGraphOptions.cs index 3dee707..4847b93 100644 --- a/src/ImageWizard.OpenGraph/Loaders/OpenGraphOptions.cs +++ b/src/ImageWizard.OpenGraph/Loaders/OpenGraphOptions.cs @@ -2,8 +2,6 @@ // https://github.com/usercode/ImageWizard // MIT License -using System; - namespace ImageWizard.Loaders; public class OpenGraphOptions : LoaderOptions diff --git a/src/ImageWizard.OpenStreetMap/Loaders/OpenStreetMapExtensions.cs b/src/ImageWizard.OpenStreetMap/Loaders/OpenStreetMapExtensions.cs index ef6fa20..8761702 100644 --- a/src/ImageWizard.OpenStreetMap/Loaders/OpenStreetMapExtensions.cs +++ b/src/ImageWizard.OpenStreetMap/Loaders/OpenStreetMapExtensions.cs @@ -7,8 +7,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; -using System; -using System.Net.Http; using System.Net.Http.Headers; namespace ImageWizard; diff --git a/src/ImageWizard.OpenStreetMap/Loaders/OpenStreetMapLoader.cs b/src/ImageWizard.OpenStreetMap/Loaders/OpenStreetMapLoader.cs index 41e5737..5149798 100644 --- a/src/ImageWizard.OpenStreetMap/Loaders/OpenStreetMapLoader.cs +++ b/src/ImageWizard.OpenStreetMap/Loaders/OpenStreetMapLoader.cs @@ -5,9 +5,6 @@ using ImageWizard.Loaders; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using System; -using System.Net.Http; -using System.Threading.Tasks; namespace ImageWizard.OpenStreetMap; diff --git a/src/ImageWizard.OpenStreetMap/Loaders/OpenStreetMapOptions.cs b/src/ImageWizard.OpenStreetMap/Loaders/OpenStreetMapOptions.cs index 35ec91c..9ce8b7c 100644 --- a/src/ImageWizard.OpenStreetMap/Loaders/OpenStreetMapOptions.cs +++ b/src/ImageWizard.OpenStreetMap/Loaders/OpenStreetMapOptions.cs @@ -3,7 +3,6 @@ // MIT License using ImageWizard.Loaders; -using System; namespace ImageWizard.OpenStreetMap; diff --git a/src/ImageWizard.Playwright/Extensions.cs b/src/ImageWizard.Playwright/Extensions.cs index f41a267..cdbb17c 100644 --- a/src/ImageWizard.Playwright/Extensions.cs +++ b/src/ImageWizard.Playwright/Extensions.cs @@ -4,7 +4,6 @@ using ImageWizard.Playwright; using Microsoft.Extensions.DependencyInjection; -using System; namespace ImageWizard; diff --git a/src/ImageWizard.Playwright/Loaders/PlaywrightOptions.cs b/src/ImageWizard.Playwright/Loaders/PlaywrightOptions.cs index 5ee2b2d..4eff338 100644 --- a/src/ImageWizard.Playwright/Loaders/PlaywrightOptions.cs +++ b/src/ImageWizard.Playwright/Loaders/PlaywrightOptions.cs @@ -3,7 +3,6 @@ // MIT License using ImageWizard.Loaders; -using System; namespace ImageWizard.Playwright; diff --git a/src/ImageWizard.Playwright/Loaders/ScreenshotLoader.cs b/src/ImageWizard.Playwright/Loaders/ScreenshotLoader.cs index ba9986f..5c48f9c 100644 --- a/src/ImageWizard.Playwright/Loaders/ScreenshotLoader.cs +++ b/src/ImageWizard.Playwright/Loaders/ScreenshotLoader.cs @@ -5,7 +5,6 @@ using ImageWizard.Loaders; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Microsoft.Playwright; namespace ImageWizard.Playwright; diff --git a/src/ImageWizard.PuppeteerSharp/Extensions.cs b/src/ImageWizard.PuppeteerSharp/Extensions.cs index 351fdf9..4582697 100644 --- a/src/ImageWizard.PuppeteerSharp/Extensions.cs +++ b/src/ImageWizard.PuppeteerSharp/Extensions.cs @@ -4,7 +4,6 @@ using ImageWizard.PuppeteerSharp; using Microsoft.Extensions.DependencyInjection; -using System; namespace ImageWizard; diff --git a/src/ImageWizard.PuppeteerSharp/Loaders/PuppeteerOptions.cs b/src/ImageWizard.PuppeteerSharp/Loaders/PuppeteerOptions.cs index 8ab1943..7070e93 100644 --- a/src/ImageWizard.PuppeteerSharp/Loaders/PuppeteerOptions.cs +++ b/src/ImageWizard.PuppeteerSharp/Loaders/PuppeteerOptions.cs @@ -3,7 +3,6 @@ // MIT License using ImageWizard.Loaders; -using System; namespace ImageWizard.PuppeteerSharp; diff --git a/src/ImageWizard.SvgNet/Builder/SvgNetBuilderExtensions.cs b/src/ImageWizard.SvgNet/Builder/SvgNetBuilderExtensions.cs index 648fea2..1d4cfe7 100644 --- a/src/ImageWizard.SvgNet/Builder/SvgNetBuilderExtensions.cs +++ b/src/ImageWizard.SvgNet/Builder/SvgNetBuilderExtensions.cs @@ -7,7 +7,6 @@ using ImageWizard.SvgNet.Builder; using ImageWizard.SvgNet.Filters; using Microsoft.Extensions.DependencyInjection; -using System; namespace ImageWizard; diff --git a/src/ImageWizard.SvgNet/Filters/Base/SvgFilterContext.cs b/src/ImageWizard.SvgNet/Filters/Base/SvgFilterContext.cs index 71deff3..479bfdc 100644 --- a/src/ImageWizard.SvgNet/Filters/Base/SvgFilterContext.cs +++ b/src/ImageWizard.SvgNet/Filters/Base/SvgFilterContext.cs @@ -4,12 +4,8 @@ using ImageWizard.Processing; using ImageWizard.Processing.Results; -using Svg; -using Svg.FilterEffects; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; +using ImageWizard.SvgNet; +using System.Xml.Linq; namespace ImageWizard.Filters; @@ -19,53 +15,68 @@ namespace ImageWizard.Filters; public class SvgFilterContext : FilterContext { public SvgFilterContext( - PipelineContext processingContext, - SvgDocument image) + PipelineContext processingContext, + XDocument image) : base(processingContext) { - Image = image; - Filters = new List(); + Document = image; + + Root = Document.Root ?? throw new ArgumentNullException(); } /// /// Image /// - public SvgDocument Image { get; } + public XDocument Document { get; } + + /// + /// Image + /// + public XElement Root { get; } /// /// Filters /// - public IList Filters { get; set; } + public IList Filters { get; set; } = new List(); public override async Task BuildResultAsync() { //apply filters if (Filters.Any()) { - var defs = Image.Children.GetSvgElementOf(); - - if (defs == null) + if (Root.Attribute("filter") == null) { - defs = new SvgDefinitionList(); - Image.Children.Add(defs); + Root.Add(new XAttribute("filter", $"url(#filter01)")); } - var filterElement = new Svg.FilterEffects.SvgFilter(); - filterElement.ID = "filter01"; + XName defName = SvgConstants.SvgNs + "defs"; + XName filterName = SvgConstants.SvgNs + "filter"; - defs.Children.Add(filterElement); + XElement? def = Root.Element(defName); - foreach (var f in Filters) + if (def == null) { - filterElement.Children.Add(f); + def = new XElement(defName); + Root.Add(def); } - Image.CustomAttributes.Add("filter", $"url(#{filterElement.ID})"); + XElement? filter = def.Element(filterName); + + if (filter == null) + { + filter = new XElement(filterName, new XAttribute("id", "filter01")); + def.Add(filter); + } + + foreach (XElement f in Filters) + { + filter.Add(f); + } } Stream mem = ProcessingContext.StreamPool.GetStream(); - Image.Write(mem); + Document.Save(mem); mem.Seek(0, SeekOrigin.Begin); diff --git a/src/ImageWizard.SvgNet/Filters/BlurFilter.cs b/src/ImageWizard.SvgNet/Filters/BlurFilter.cs index 4355eb8..3df83aa 100644 --- a/src/ImageWizard.SvgNet/Filters/BlurFilter.cs +++ b/src/ImageWizard.SvgNet/Filters/BlurFilter.cs @@ -3,8 +3,8 @@ // MIT License using ImageWizard.Attributes; -using Svg; -using Svg.FilterEffects; +using System.Globalization; +using System.Xml.Linq; namespace ImageWizard.SvgNet.Filters; @@ -19,9 +19,7 @@ public void Blur() [Filter] public void Blur(float deviation) { - var l = new SvgNumberCollection(); - l.Add(deviation); - - Context.Filters.Add(new SvgGaussianBlur() { StdDeviation = l }); + Context.Filters.Add(new XElement(SvgConstants.SvgNs + "feGaussianBlur", + new XAttribute("stdDeviation", deviation.ToString(CultureInfo.InvariantCulture)))); } -} +} \ No newline at end of file diff --git a/src/ImageWizard.SvgNet/Filters/GrayscaleFilter.cs b/src/ImageWizard.SvgNet/Filters/GrayscaleFilter.cs index 3ff59df..d68c8c3 100644 --- a/src/ImageWizard.SvgNet/Filters/GrayscaleFilter.cs +++ b/src/ImageWizard.SvgNet/Filters/GrayscaleFilter.cs @@ -3,7 +3,7 @@ // MIT License using ImageWizard.Attributes; -using Svg.FilterEffects; +using System.Xml.Linq; namespace ImageWizard.SvgNet.Filters; @@ -12,13 +12,9 @@ public class GrayscaleFilter : ImageWizard.Filters.SvgFilter [Filter] public void Grayscale() { - Context.Filters.Add(new SvgColourMatrix() { Type = SvgColourMatrixType.Matrix, - Values = - @"0.21 0.72 0.07 0 0 - 0.21 0.72 0.07 0 0 - 0.21 0.72 0.07 0 0 - 0 0 0 1 0" - }); + Context.Filters.Add(new XElement(SvgConstants.SvgNs + "feColorMatrix", + new XAttribute("type", "matrix"), + new XAttribute("values", "0.21 0.72 0.07 0 0 0.21 0.72 0.07 0 0 0.21 0.72 0.07 0 0 0 0 0 1 0"))); } } diff --git a/src/ImageWizard.SvgNet/Filters/ImageFormatFilter.cs b/src/ImageWizard.SvgNet/Filters/ImageFormatFilter.cs deleted file mode 100644 index 0bc438f..0000000 --- a/src/ImageWizard.SvgNet/Filters/ImageFormatFilter.cs +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) usercode -// https://github.com/usercode/ImageWizard -// MIT License - -using ImageWizard.Attributes; -using ImageWizard.Processing.Results; -using System; -using System.Drawing.Imaging; -using System.IO; - -namespace ImageWizard.SvgNet.Filters; - -public class ImageFormatFilter : ImageWizard.Filters.SvgFilter -{ - [Filter] - public void Png() - { - SaveToImage(ImageFormat.Png); - } - - [Filter] - public void Jpg() - { - SaveToImage(ImageFormat.Jpeg); - } - - [Filter] - public void Gif() - { - SaveToImage(ImageFormat.Gif); - } - - [Filter] - public void Bmp() - { - SaveToImage(ImageFormat.Bmp); - } - - private void SaveToImage(ImageFormat format) - { - var bitmap = Context.Image.Draw(); - - Stream mem = Context.ProcessingContext.StreamPool.GetStream(); - - bitmap.Save(mem, format); - - mem.Seek(0, SeekOrigin.Begin); - - string mimeType; - - if (format == ImageFormat.Png) - { - mimeType = MimeTypes.Png; - } - else if (format == ImageFormat.Jpeg) - { - mimeType = MimeTypes.Jpeg; - } - else if (format == ImageFormat.Gif) - { - mimeType = MimeTypes.Gif; - } - else if (format == ImageFormat.Bmp) - { - mimeType = MimeTypes.Bmp; - } - else - { - throw new Exception(); - } - - Context.Result = new DataResult(mem, mimeType); - } -} diff --git a/src/ImageWizard.SvgNet/Filters/InvertFilter.cs b/src/ImageWizard.SvgNet/Filters/InvertFilter.cs index 44965a7..62f51a0 100644 --- a/src/ImageWizard.SvgNet/Filters/InvertFilter.cs +++ b/src/ImageWizard.SvgNet/Filters/InvertFilter.cs @@ -3,7 +3,7 @@ // MIT License using ImageWizard.Attributes; -using Svg.FilterEffects; +using System.Xml.Linq; namespace ImageWizard.SvgNet.Filters; @@ -12,9 +12,9 @@ public class InvertFilter : ImageWizard.Filters.SvgFilter [Filter] public void Invert() { - Context.Filters.Add(new SvgColourMatrix() { Type = SvgColourMatrixType.Matrix, - Values = "-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0 " - }); + Context.Filters.Add(new XElement(SvgConstants.SvgNs + "feColorMatrix", + new XAttribute("type", "matrix"), + new XAttribute("values", "-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0"))); } } diff --git a/src/ImageWizard.SvgNet/Filters/RemoveSizeFilter.cs b/src/ImageWizard.SvgNet/Filters/RemoveSizeFilter.cs index d1e2ca0..84e2a81 100644 --- a/src/ImageWizard.SvgNet/Filters/RemoveSizeFilter.cs +++ b/src/ImageWizard.SvgNet/Filters/RemoveSizeFilter.cs @@ -4,7 +4,7 @@ using ImageWizard.Attributes; using ImageWizard.Filters; -using Svg; +using System.Xml.Linq; namespace ImageWizard.SvgNet.Filters; @@ -13,8 +13,18 @@ public class RemoveSizeFilter : SvgFilter [Filter] public void RemoveSize() { - Context.Image.Width = SvgUnit.None; - Context.Image.Height = SvgUnit.None; - } + XAttribute? width = Context.Root.Attribute("width"); + + if (width != null) + { + width.Remove(); + } + XAttribute? height = Context.Root.Attribute("height"); + + if (height != null) + { + height.Remove(); + } + } } diff --git a/src/ImageWizard.SvgNet/Filters/RotateFilter.cs b/src/ImageWizard.SvgNet/Filters/RotateFilter.cs index ae040fd..16b423f 100644 --- a/src/ImageWizard.SvgNet/Filters/RotateFilter.cs +++ b/src/ImageWizard.SvgNet/Filters/RotateFilter.cs @@ -3,7 +3,8 @@ // MIT License using ImageWizard.Attributes; -using Svg.Transforms; +using System.Globalization; +using System.Xml.Linq; namespace ImageWizard.SvgNet.Filters; @@ -12,7 +13,8 @@ public class RotateFilter : ImageWizard.Filters.SvgFilter [Filter] public void Rotate(float angle) { - Context.Image.Transforms.Add(new SvgRotate(angle)); + Context.Root.Add(new XAttribute("transform", + $"rotate({angle.ToString(CultureInfo.InvariantCulture)})")); } } diff --git a/src/ImageWizard.SvgNet/Filters/SaturateFilter.cs b/src/ImageWizard.SvgNet/Filters/SaturateFilter.cs index cbcbd33..d025633 100644 --- a/src/ImageWizard.SvgNet/Filters/SaturateFilter.cs +++ b/src/ImageWizard.SvgNet/Filters/SaturateFilter.cs @@ -3,8 +3,8 @@ // MIT License using ImageWizard.Attributes; -using Svg.FilterEffects; using System.Globalization; +using System.Xml.Linq; namespace ImageWizard.SvgNet.Filters; @@ -13,8 +13,8 @@ public class SaturateFilter : ImageWizard.Filters.SvgFilter [Filter] public void Saturate(float value) { - Context.Filters.Add(new SvgColourMatrix() { Type = SvgColourMatrixType.Saturate, - Values = value.ToString("0.0##", CultureInfo.InvariantCulture) - }); + Context.Filters.Add(new XElement(SvgConstants.SvgNs + "feColorMatrix", + new XAttribute("type", "saturate"), + new XAttribute("values", value.ToString(CultureInfo.InvariantCulture)))); } } diff --git a/src/ImageWizard.SvgNet/ImageWizard.SvgNet.csproj b/src/ImageWizard.SvgNet/ImageWizard.SvgNet.csproj index 7181a16..f37fb79 100644 --- a/src/ImageWizard.SvgNet/ImageWizard.SvgNet.csproj +++ b/src/ImageWizard.SvgNet/ImageWizard.SvgNet.csproj @@ -20,10 +20,6 @@ - - - - diff --git a/src/ImageWizard.SvgNet/ImageWizardBuilderExtensions.cs b/src/ImageWizard.SvgNet/ImageWizardBuilderExtensions.cs index 0aae94a..0e348ce 100644 --- a/src/ImageWizard.SvgNet/ImageWizardBuilderExtensions.cs +++ b/src/ImageWizard.SvgNet/ImageWizardBuilderExtensions.cs @@ -4,7 +4,6 @@ using ImageWizard.SvgNet.Builder; using ImageWizard.SvgNet.Filters; -using System; namespace ImageWizard; @@ -23,7 +22,6 @@ public static IImageWizardBuilder AddSvgNet(this IImageWizardBuilder builder, Ac pipelineBuilder.WithFilter(); pipelineBuilder.WithFilter(); pipelineBuilder.WithFilter(); - pipelineBuilder.WithFilter(); pipelineBuilder.WithMimeTypes(MimeTypes.Svg); diff --git a/src/ImageWizard.SvgNet/SvgConstants.cs b/src/ImageWizard.SvgNet/SvgConstants.cs new file mode 100644 index 0000000..ea85008 --- /dev/null +++ b/src/ImageWizard.SvgNet/SvgConstants.cs @@ -0,0 +1,12 @@ +// Copyright (c) usercode +// https://github.com/usercode/ImageWizard +// MIT License + +using System.Xml.Linq; + +namespace ImageWizard.SvgNet; + +public static class SvgConstants +{ + public static readonly XNamespace SvgNs = XNamespace.Get("http://www.w3.org/2000/svg"); +} diff --git a/src/ImageWizard.SvgNet/SvgPipeline.cs b/src/ImageWizard.SvgNet/SvgPipeline.cs index 89d0fa3..1677129 100644 --- a/src/ImageWizard.SvgNet/SvgPipeline.cs +++ b/src/ImageWizard.SvgNet/SvgPipeline.cs @@ -5,11 +5,7 @@ using ImageWizard.Filters; using ImageWizard.Processing; using Microsoft.Extensions.Logging; -using Svg; -using Svg.Transforms; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; +using System.Xml.Linq; namespace ImageWizard.SvgNet.Filters; @@ -30,9 +26,7 @@ public SvgPipeline( protected override async Task CreateFilterContext(PipelineContext context) { //load image - SvgDocument svg = SvgDocument.Open(context.Result.Data); - - svg.Transforms = new SvgTransformCollection(); + XDocument svg = XDocument.Load(context.Result.Data); return new SvgFilterContext(context, svg); } diff --git a/src/ImageWizard.TestApp/Pages/Index.cshtml b/src/ImageWizard.TestApp/Pages/Index.cshtml index b7dfb5c..835b5bd 100644 --- a/src/ImageWizard.TestApp/Pages/Index.cshtml +++ b/src/ImageWizard.TestApp/Pages/Index.cshtml @@ -74,6 +74,10 @@

Saturate(0.3)

+
+

Combine filters (grayscale, rotate, invert)

+ +

ImageSharp filters

diff --git a/src/ImageWizard/Dockerfile b/src/ImageWizard/Dockerfile index 12f1696..0fb2009 100644 --- a/src/ImageWizard/Dockerfile +++ b/src/ImageWizard/Dockerfile @@ -1,12 +1,6 @@ #See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base -RUN sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list -RUN apt-get update -RUN apt-get install -y ttf-mscorefonts-installer fontconfig -RUN apt-get install -y --no-install-recommends libgdiplus libc6-dev \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* WORKDIR /app EXPOSE 8080 EXPOSE 8081 diff --git a/src/ImageWizard/Program.cs b/src/ImageWizard/Program.cs index a1715d8..5e1217f 100644 --- a/src/ImageWizard/Program.cs +++ b/src/ImageWizard/Program.cs @@ -2,20 +2,99 @@ // https://github.com/usercode/ImageWizard // MIT License -using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Options; +using SixLabors.ImageSharp.Metadata.Profiles.Exif; +using SixLabors.ImageSharp.Processing; +using ImageWizard.ImageSharp; +using JpegFormat = ImageWizard.ImageSharp.JpegFormat; +using PngFormat = ImageWizard.ImageSharp.PngFormat; +using ImageWizard.ImageSharp.Filters; +using ImageWizard; +using ImageWizard.Loaders; +using ImageWizard.Caches; +using ImageWizard.Azure; +using Microsoft.AspNetCore.HttpOverrides; -namespace ImageWizard; +var builder = WebApplication.CreateBuilder(args); -public class Program +builder.Services.AddOptions().BindConfiguration("App"); +builder.Services.AddOptions().BindConfiguration("General"); +builder.Services.AddOptions().BindConfiguration("HttpLoader"); +builder.Services.AddOptions().BindConfiguration("FileCache"); +builder.Services.AddOptions().BindConfiguration("FileLoader"); +builder.Services.AddOptions().BindConfiguration("Azure"); +builder.Services.AddOptions().BindConfiguration("Watermark"); + +IImageWizardBuilder imageWizard = builder.Services.AddImageWizard() + .AddImageSharp(i => i + .WithPreProcessing(x => + { + x.Image.Mutate(m => m.AutoOrient()); + }) + .WithPostProcessing(x => + { + IOptions options = x.ProcessingContext + .ServiceProvider.GetRequiredService>(); + + if (options.Value.UseWebP) + { + if (x.ImageFormat is JpegFormat) + { + x.ImageFormat = new WebPFormat() { Lossless = false }; + } + else if (x.ImageFormat is PngFormat) + { + x.ImageFormat = new WebPFormat() { Lossless = true }; + } + } + + if (options.Value.AddMetadata) + { + x.Image.Metadata.ExifProfile = new ExifProfile(); + x.Image.Metadata.ExifProfile.SetValue(ExifTag.Copyright, options.Value.MetadataCopyright); + } + })) + .AddSvgNet() + .AddDocNET() + .AddHttpLoader() + .AddFileLoader() + .AddYoutubeLoader() + .AddGravatarLoader() + .AddAzureLoader() + .AddOpenGraphLoader() + .AddAnalytics() + .SetFileCache() + ; + +builder.Services.Configure(options => { - public static void Main(string[] args) - { - CreateWebHostBuilder(args).Build().Run(); - } + options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost; + options.KnownNetworks.Clear(); + options.KnownProxies.Clear(); +}); +builder.Services.AddHttpsRedirection(x => x.HttpsPort = 443); + +var app = builder.Build(); - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup() - ; +var options = app.Services.GetRequiredService>(); +var env = app.Services.GetRequiredService(); + +if (env.IsDevelopment()) +{ + app.UseDeveloperExceptionPage(); } + +app.UseForwardedHeaders(); +app.UseHttpsRedirection(); +app.UseImageWizard(x => +{ + if (options.Value.UseAnalytics) + { + x.MapAnalytics(); + } +}); +await app.RunAsync(); diff --git a/src/ImageWizard/Startup.cs b/src/ImageWizard/Startup.cs deleted file mode 100644 index 77de91b..0000000 --- a/src/ImageWizard/Startup.cs +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) usercode -// https://github.com/usercode/ImageWizard -// MIT License - -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Options; -using Microsoft.AspNetCore.HttpOverrides; -using ImageWizard.Caches; -using ImageWizard.Loaders; -using ImageWizard.Azure; -using SixLabors.ImageSharp.Metadata.Profiles.Exif; -using SixLabors.ImageSharp.Processing; -using ImageWizard.ImageSharp; -using JpegFormat = ImageWizard.ImageSharp.JpegFormat; -using PngFormat = ImageWizard.ImageSharp.PngFormat; -using ImageWizard.ImageSharp.Filters; - -namespace ImageWizard; - -public class Startup -{ - public Startup(IConfiguration configuration, IWebHostEnvironment env) - { - Configuration = configuration; - HostingEnvironment = env; - } - - public IConfiguration Configuration { get; } - - public IWebHostEnvironment HostingEnvironment { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddOptions().BindConfiguration("App"); - services.AddOptions().BindConfiguration("General"); - services.AddOptions().BindConfiguration("HttpLoader"); - services.AddOptions().BindConfiguration("FileCache"); - services.AddOptions().BindConfiguration("FileLoader"); - services.AddOptions().BindConfiguration("Azure"); - services.AddOptions().BindConfiguration("Watermark"); - - IImageWizardBuilder imageWizard = services.AddImageWizard() - .AddImageSharp(i => i - .WithPreProcessing(x => - { - x.Image.Mutate(m => m.AutoOrient()); - }) - .WithPostProcessing(x => - { - IOptions options = x.ProcessingContext - .ServiceProvider.GetRequiredService>(); - - if (options.Value.UseWebP) - { - if (x.ImageFormat is JpegFormat) - { - x.ImageFormat = new WebPFormat() { Lossless = false }; - } - else if(x.ImageFormat is PngFormat) - { - x.ImageFormat = new WebPFormat() { Lossless = true }; - } - } - - if (options.Value.AddMetadata) - { - x.Image.Metadata.ExifProfile = new ExifProfile(); - x.Image.Metadata.ExifProfile.SetValue(ExifTag.Copyright, options.Value.MetadataCopyright); - } - })) - .AddSvgNet() - .AddDocNET() - .AddHttpLoader() - .AddFileLoader() - .AddYoutubeLoader() - .AddGravatarLoader() - .AddAzureLoader() - .AddOpenGraphLoader() - .AddAnalytics() - .SetFileCache() - ; - - services.Configure(options => - { - options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost; - options.KnownNetworks.Clear(); - options.KnownProxies.Clear(); - }); - services.AddHttpsRedirection(x => x.HttpsPort = 443); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IOptions options) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - - app.UseForwardedHeaders(); - app.UseHttpsRedirection(); - app.UseImageWizard(x => - { - if (options.Value.UseAnalytics) - { - x.MapAnalytics(); - } - }); - } -} diff --git a/src/ImageWizard/appsettings.json b/src/ImageWizard/appsettings.json index def9159..697c15b 100644 --- a/src/ImageWizard/appsettings.json +++ b/src/ImageWizard/appsettings.json @@ -1,7 +1,10 @@ { "Logging": { "LogLevel": { - "Default": "Warning" + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information", + "System.Net.Http.HttpClient": "Warning" } }, "AllowedHosts": "*"