You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sonarr/src/NzbDrone.Core/MediaCover/ImageResizer.cs

50 lines
1.3 KiB

using ImageResizer;
using NzbDrone.Common.Disk;
namespace NzbDrone.Core.MediaCover
{
public interface IImageResizer
{
void Resize(string source, string destination, int height);
}
public class ImageResizer : IImageResizer
{
private readonly IDiskProvider _diskProvider;
public ImageResizer(IDiskProvider diskProvider)
{
_diskProvider = diskProvider;
}
public void Resize(string source, string destination, int height)
{
try
{
GdiPlusInterop.CheckGdiPlus();
using (var sourceStream = _diskProvider.OpenReadStream(source))
{
using (var outputStream = _diskProvider.OpenWriteStream(destination))
{
var settings = new Instructions();
settings.Height = height;
var job = new ImageJob(sourceStream, outputStream, settings);
ImageBuilder.Current.Build(job);
}
}
}
catch
{
if (_diskProvider.FileExists(destination))
{
_diskProvider.DeleteFile(destination);
}
throw;
}
}
}
}