ImgMetadataRemover/ImageCore/Core/ExifRemoverAndCompressor.cs

59 lines
1.7 KiB
C#
Raw Permalink Normal View History

using System.IO;
using ImageMagick;
2022-01-23 13:12:17 +00:00
namespace Image.Core
2022-01-23 13:12:17 +00:00
{
2022-01-23 17:30:05 +00:00
/// <summary>
2022-02-12 20:12:57 +00:00
/// ExifRemoverAndCompressor removes exif metadata from an image.
2022-01-23 17:30:05 +00:00
/// </summary>
2022-02-12 20:12:57 +00:00
public class ExifRemoverAndCompressor : IMetadataRemover
2022-01-23 13:12:17 +00:00
{
private readonly ICompressor _compressor;
private readonly IMagickImage _magickImage;
2022-01-23 17:30:05 +00:00
/// <summary>
2022-02-12 20:12:57 +00:00
/// Constructs an instance of ExifRemoverAndCompressor.
2022-01-23 17:30:05 +00:00
/// </summary>
/// <param name="magickImage">MagicImage instance.</param>
/// <param name="compressor">Compressor instance.</param>
2022-02-12 20:12:57 +00:00
public ExifRemoverAndCompressor(IMagickImage magickImage, ICompressor compressor)
2022-01-23 13:12:17 +00:00
{
_magickImage = magickImage;
_compressor = compressor;
}
2022-01-23 17:30:05 +00:00
/// <summary>
/// Cleans the image.
2022-01-23 17:30:05 +00:00
/// </summary>
public void CleanImage()
2022-01-23 13:12:17 +00:00
{
_magickImage.RemoveProfile("exif");
}
/// <summary>
/// Save the image under a new file path.
/// </summary>
/// <param name="newFilePath">The new path of the image.</param>
public void SaveImage(string newFilePath)
{
2022-01-23 17:30:05 +00:00
_magickImage.Write(newFilePath);
_compressor.Compress(newFilePath);
2022-01-23 13:12:17 +00:00
}
/// <inheritdoc />
public string GetImagePath()
{
return _magickImage.FileName;
}
/// <summary>
/// Saves the image.
/// </summary>
/// <param name="stream">The stream.</param>
public void SaveImage(Stream stream)
{
_magickImage.Write(stream);
_compressor.Compress(stream);
}
2022-01-23 13:12:17 +00:00
}
}