2022-04-03 15:16:00 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using ImageMagick;
|
2022-01-23 13:12:17 +00:00
|
|
|
|
|
2022-02-11 21:39:34 +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>
|
2022-04-03 15:16:00 +00:00
|
|
|
|
/// Cleans the image.
|
2022-01-23 17:30:05 +00:00
|
|
|
|
/// </summary>
|
2022-04-03 15:16:00 +00:00
|
|
|
|
public void CleanImage()
|
2022-01-23 13:12:17 +00:00
|
|
|
|
{
|
|
|
|
|
_magickImage.RemoveProfile("exif");
|
2022-04-03 15:16:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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
|
|
|
|
}
|
2022-02-12 21:25:34 +00:00
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public string GetImagePath()
|
|
|
|
|
{
|
|
|
|
|
return _magickImage.FileName;
|
|
|
|
|
}
|
2022-04-03 15:16:00 +00:00
|
|
|
|
|
|
|
|
|
/// <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
|
|
|
|
}
|
|
|
|
|
}
|