Skip to content

Commit

Permalink
Removed dependency to Svg package
Browse files Browse the repository at this point in the history
  • Loading branch information
usercode committed Dec 12, 2023
1 parent cf507fa commit 548c799
Show file tree
Hide file tree
Showing 49 changed files with 185 additions and 326 deletions.
1 change: 0 additions & 1 deletion src/ImageWizard.AWS/AwsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using ImageWizard.AWS;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace ImageWizard;

Expand Down
1 change: 0 additions & 1 deletion src/ImageWizard.AWS/AwsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Amazon.S3.Model;
using ImageWizard.Loaders;
using Microsoft.Extensions.Options;
using System.Threading.Tasks;

namespace ImageWizard.AWS;

Expand Down
2 changes: 0 additions & 2 deletions src/ImageWizard.Analytics/AnalyticsData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// https://github.com/usercode/ImageWizard
// MIT License

using System.Collections.Generic;

namespace ImageWizard.Analytics;

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions src/ImageWizard.Analytics/ImageRequestAnalytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// https://github.com/usercode/ImageWizard
// MIT License

using System;

namespace ImageWizard.Analytics;

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/ImageWizard.Azure/AzureBlobExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using ImageWizard.Azure;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace ImageWizard;

Expand Down
1 change: 0 additions & 1 deletion src/ImageWizard.Azure/AzureBlobLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Azure.Storage.Blobs.Models;
using ImageWizard.Loaders;
using Microsoft.Extensions.Options;
using System.Threading.Tasks;

namespace ImageWizard.Azure;

Expand Down
3 changes: 0 additions & 3 deletions src/ImageWizard.DocNET/DocNETPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions src/ImageWizard.DocNET/Filters/Base/DocNETFilterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

using ImageWizard.Processing;
using ImageWizard.Processing.Results;
using System.IO;
using System.Threading.Tasks;

namespace ImageWizard.DocNET.Filters.Base;

Expand Down
1 change: 0 additions & 1 deletion src/ImageWizard.DocNET/Filters/PageToImageFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using ImageWizard.Processing.Results;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System.IO;

namespace ImageWizard.DocNET.Filters;

Expand Down
1 change: 0 additions & 1 deletion src/ImageWizard.DocNET/Filters/SubPagesFIlter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using ImageWizard.Attributes;
using ImageWizard.DocNET.Filters.Base;
using ImageWizard.Processing.Results;
using System.IO;

namespace ImageWizard.DocNET.Filters;

Expand Down
1 change: 0 additions & 1 deletion src/ImageWizard.DocNET/ImageWizardBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using ImageWizard.DocNET;
using ImageWizard.DocNET.Builder;
using ImageWizard.DocNET.Filters;
using System;

namespace ImageWizard;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using ImageWizard.FFMpegCore.Builder;
using ImageWizard.FFMpegCore.Filters.Base;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace ImageWizard;

Expand Down
1 change: 0 additions & 1 deletion src/ImageWizard.FFMpegCore/FFMpegExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using ImageWizard.FFMpegCore;
using ImageWizard.FFMpegCore.Builder;
using ImageWizard.FFMpegCore.Filters;
using System;

namespace ImageWizard;

Expand Down
3 changes: 0 additions & 3 deletions src/ImageWizard.FFMpegCore/FFMpegPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions src/ImageWizard.FFMpegCore/Filters/Base/FFMpegContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

using ImageWizard.Processing;
using ImageWizard.Processing.Results;
using System;
using System.Threading.Tasks;

namespace ImageWizard.FFMpegCore.Filters.Base;

Expand Down
1 change: 0 additions & 1 deletion src/ImageWizard.FFMpegCore/Filters/FrameFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using ImageWizard.Attributes;
using ImageWizard.FFMpegCore.Filters.Base;
using ImageWizard.Processing.Results;
using System.IO;

namespace ImageWizard.FFMpegCore.Filters;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ namespace ImageWizard;
public static class ImageSharpBuilderExtensions
{
/// <summary>
/// Registers an ImageSharp filter.
/// Registers the <typeparamref name="TFilter"/> filter.
/// </summary>
/// <typeparam name="TFilter"></typeparam>
/// <param name="builder"></param>
/// <returns></returns>
public static IImageSharpBuilder WithFilter<TFilter>(this IImageSharpBuilder builder)
where TFilter : ImageSharpFilter
{
Expand Down
4 changes: 2 additions & 2 deletions src/ImageWizard.MongoDB/ImageWizard.MongoDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.22.0" />
<PackageReference Include="MongoDB.Driver.GridFS" Version="2.22.0" />
<PackageReference Include="MongoDB.Driver" Version="2.23.0" />
<PackageReference Include="MongoDB.Driver.GridFS" Version="2.23.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

using ImageWizard.Processing;
using ImageWizard.Processing.Results;
using System;
using System.Threading.Tasks;

namespace ImageWizard.OpenCvSharp.Filters;

Expand Down
3 changes: 0 additions & 3 deletions src/ImageWizard.OpenCvSharp/OpenCvSharpPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion src/ImageWizard.OpenGraph/Loaders/OpenGraphExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using ImageWizard.Loaders;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace ImageWizard;

Expand Down
3 changes: 0 additions & 3 deletions src/ImageWizard.OpenGraph/Loaders/OpenGraphLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions src/ImageWizard.OpenGraph/Loaders/OpenGraphOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// https://github.com/usercode/ImageWizard
// MIT License

using System;

namespace ImageWizard.Loaders;

public class OpenGraphOptions : LoaderOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/ImageWizard.OpenStreetMap/Loaders/OpenStreetMapLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// MIT License

using ImageWizard.Loaders;
using System;

namespace ImageWizard.OpenStreetMap;

Expand Down
1 change: 0 additions & 1 deletion src/ImageWizard.Playwright/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using ImageWizard.Playwright;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace ImageWizard;

Expand Down
1 change: 0 additions & 1 deletion src/ImageWizard.Playwright/Loaders/PlaywrightOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// MIT License

using ImageWizard.Loaders;
using System;

namespace ImageWizard.Playwright;

Expand Down
1 change: 0 additions & 1 deletion src/ImageWizard.Playwright/Loaders/ScreenshotLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using ImageWizard.Loaders;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Playwright;

namespace ImageWizard.Playwright;

Expand Down
1 change: 0 additions & 1 deletion src/ImageWizard.PuppeteerSharp/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using ImageWizard.PuppeteerSharp;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace ImageWizard;

Expand Down
1 change: 0 additions & 1 deletion src/ImageWizard.PuppeteerSharp/Loaders/PuppeteerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// MIT License

using ImageWizard.Loaders;
using System;

namespace ImageWizard.PuppeteerSharp;

Expand Down
1 change: 0 additions & 1 deletion src/ImageWizard.SvgNet/Builder/SvgNetBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using ImageWizard.SvgNet.Builder;
using ImageWizard.SvgNet.Filters;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace ImageWizard;

Expand Down
59 changes: 35 additions & 24 deletions src/ImageWizard.SvgNet/Filters/Base/SvgFilterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<SvgFilterPrimitive>();
Document = image;

Root = Document.Root ?? throw new ArgumentNullException();
}

/// <summary>
/// Image
/// </summary>
public SvgDocument Image { get; }
public XDocument Document { get; }

/// <summary>
/// Image
/// </summary>
public XElement Root { get; }

/// <summary>
/// Filters
/// </summary>
public IList<SvgFilterPrimitive> Filters { get; set; }
public IList<XElement> Filters { get; set; } = new List<XElement>();

public override async Task<DataResult> BuildResultAsync()
{
//apply filters
if (Filters.Any())
{
var defs = Image.Children.GetSvgElementOf<SvgDefinitionList>();

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);

Expand Down
Loading

0 comments on commit 548c799

Please sign in to comment.