ImgMetadataRemover/ImageCore/Core/ExifRemoverAndCompressor.cs

41 lines
1.3 KiB
C#
Raw Normal View History

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 images and compresses it.
/// </summary>
/// <param name="newFilePath">The file path to save the clean image.</param>
public void CleanImage(string newFilePath)
2022-01-23 13:12:17 +00:00
{
_magickImage.RemoveProfile("exif");
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;
}
2022-01-23 13:12:17 +00:00
}
}