image processor which strips metadata

This commit is contained in:
2024-03-19 13:26:24 +01:00
parent 0dc885dd07
commit ccd1db47cf
2 changed files with 53 additions and 1 deletions
@@ -0,0 +1,51 @@
using Microsoft.Extensions.Logging;
using SixLabors.ImageSharp.Web;
using SixLabors.ImageSharp.Web.Commands;
using SixLabors.ImageSharp.Web.Processors;
using System.Globalization;
namespace zero.Media.ImageSharp.Processors;
public class StripMetadataWebProcessor : IImageWebProcessor
{
// <summary>
/// The command constant for quality.
/// </summary>
public const string Strip = "strip";
/// <summary>
/// The reusable collection of commands.
/// </summary>
private static readonly IEnumerable<string> StripCommands
= new[] { Strip };
/// <inheritdoc/>
public IEnumerable<string> Commands { get; } = StripCommands;
/// <inheritdoc/>
public FormattedImage Process(
FormattedImage image,
ILogger logger,
CommandCollection commands,
CommandParser parser,
CultureInfo culture)
{
if (commands.Contains(Strip))
{
bool strip = parser.ParseValue<bool>(commands.GetValueOrDefault(Strip), culture);
if (strip)
{
image.Image.Metadata.ExifProfile = null;
image.Image.Metadata.XmpProfile = null;
image.Image.Metadata.IptcProfile = null;
image.Image.Metadata.IccProfile = null;
}
}
return image;
}
/// <inheritdoc/>
public bool RequiresTrueColorPixelFormat(CommandCollection commands, CommandParser parser, CultureInfo culture) => true;
}
+2 -1
View File
@@ -1,4 +1,5 @@
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.Web;
using System.Numerics;