mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
New: Use ImageSharp for resizing
This commit is contained in:
parent
c85d3119f9
commit
bc0cc2bfa9
@ -122,20 +122,6 @@ public bool FileExists(string path, StringComparison stringComparison)
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanUseGDIPlus()
|
||||
{
|
||||
try
|
||||
{
|
||||
GdiPlusInterop.CheckGdiPlus();
|
||||
return true;
|
||||
}
|
||||
catch (DllNotFoundException ex)
|
||||
{
|
||||
Logger.Trace(ex, "System does not have libgdiplus.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool FolderWritable(string path)
|
||||
{
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
@ -1,44 +0,0 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Common.Disk
|
||||
{
|
||||
public static class GdiPlusInterop
|
||||
{
|
||||
private static Exception _gdiPlusException;
|
||||
|
||||
static GdiPlusInterop()
|
||||
{
|
||||
TestLibrary();
|
||||
}
|
||||
|
||||
private static void TestLibrary()
|
||||
{
|
||||
if (OsInfo.IsWindows)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// We use StringFormat as test coz it gets properly cleaned up by the finalizer even if gdiplus is absent and is relatively non-invasive.
|
||||
var strFormat = new StringFormat();
|
||||
|
||||
strFormat.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_gdiPlusException = ex;
|
||||
}
|
||||
}
|
||||
|
||||
public static void CheckGdiPlus()
|
||||
{
|
||||
if (_gdiPlusException != null)
|
||||
{
|
||||
throw new DllNotFoundException("Couldn't load GDIPlus library", _gdiPlusException);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -19,7 +19,6 @@ public interface IDiskProvider
|
||||
bool FolderExists(string path);
|
||||
bool FileExists(string path);
|
||||
bool FileExists(string path, StringComparison stringComparison);
|
||||
bool CanUseGDIPlus();
|
||||
bool FolderWritable(string path);
|
||||
string[] GetDirectories(string path);
|
||||
string[] GetFiles(string path, SearchOption searchOption);
|
||||
|
@ -1,6 +1,8 @@
|
||||
using ImageResizer;
|
||||
using System;
|
||||
using NzbDrone.Common.Disk;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using SixLabors.Memory;
|
||||
|
||||
namespace NzbDrone.Core.MediaCover
|
||||
{
|
||||
@ -16,28 +18,20 @@ public class ImageResizer : IImageResizer
|
||||
public ImageResizer(IDiskProvider diskProvider)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
|
||||
// More conservative memory allocation
|
||||
SixLabors.ImageSharp.Configuration.Default.MemoryAllocator = new SimpleGcMemoryAllocator();
|
||||
}
|
||||
|
||||
public void Resize(string source, string destination, int height)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_diskProvider.CanUseGDIPlus())
|
||||
using (var image = Image.Load(source))
|
||||
{
|
||||
throw new Exception("Can't resize without libgdiplus.");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
var width = (int)Math.Floor((double)image.Width * (double)height / (double)image.Height);
|
||||
image.Mutate(x => x.Resize(width, height));
|
||||
image.Save(destination);
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
@ -7,7 +7,7 @@
|
||||
<PackageReference Include="FluentMigrator.Runner" Version="4.0.0-alpha.268" />
|
||||
<PackageReference Include="FluentMigrator.Runner.SQLite" Version="4.0.0-alpha.268" />
|
||||
<PackageReference Include="FluentValidation" Version="8.4.0" />
|
||||
<PackageReference Include="ImageResizer" Version="4.2.5" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0007" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||
<PackageReference Include="NLog" Version="4.6.7" />
|
||||
<PackageReference Include="OAuth" Version="1.0.3" />
|
||||
|
Loading…
Reference in New Issue
Block a user