2016-12-23 21:45:24 +00:00
|
|
|
|
using ImageResizer;
|
2015-01-22 22:12:35 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2015-02-03 19:46:51 +00:00
|
|
|
|
try
|
2015-01-22 22:12:35 +00:00
|
|
|
|
{
|
2016-11-05 21:17:08 +00:00
|
|
|
|
GdiPlusInterop.CheckGdiPlus();
|
|
|
|
|
|
2015-02-03 19:46:51 +00:00
|
|
|
|
using (var sourceStream = _diskProvider.OpenReadStream(source))
|
2015-01-22 22:12:35 +00:00
|
|
|
|
{
|
2015-02-03 19:46:51 +00:00
|
|
|
|
using (var outputStream = _diskProvider.OpenWriteStream(destination))
|
|
|
|
|
{
|
|
|
|
|
var settings = new Instructions();
|
|
|
|
|
settings.Height = height;
|
2015-01-22 22:12:35 +00:00
|
|
|
|
|
2015-02-03 19:46:51 +00:00
|
|
|
|
var job = new ImageJob(sourceStream, outputStream, settings);
|
2015-01-22 22:12:35 +00:00
|
|
|
|
|
2015-02-03 19:46:51 +00:00
|
|
|
|
ImageBuilder.Current.Build(job);
|
|
|
|
|
}
|
2015-01-22 22:12:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-03 19:46:51 +00:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
if (_diskProvider.FileExists(destination))
|
|
|
|
|
{
|
|
|
|
|
_diskProvider.DeleteFile(destination);
|
|
|
|
|
}
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2015-01-22 22:12:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|