diff --git a/src/NzbDrone.Core/MediaCover/GdiPlusInterop.cs b/src/NzbDrone.Core/MediaCover/GdiPlusInterop.cs new file mode 100644 index 000000000..36c5a65eb --- /dev/null +++ b/src/NzbDrone.Core/MediaCover/GdiPlusInterop.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using NzbDrone.Common.EnvironmentInfo; + +namespace NzbDrone.Core.MediaCover +{ + 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); + } + } + } +} diff --git a/src/NzbDrone.Core/MediaCover/ImageResizer.cs b/src/NzbDrone.Core/MediaCover/ImageResizer.cs index 0466c0361..9a75065ff 100644 --- a/src/NzbDrone.Core/MediaCover/ImageResizer.cs +++ b/src/NzbDrone.Core/MediaCover/ImageResizer.cs @@ -24,6 +24,8 @@ public void Resize(string source, string destination, int height) { try { + GdiPlusInterop.CheckGdiPlus(); + using (var sourceStream = _diskProvider.OpenReadStream(source)) { using (var outputStream = _diskProvider.OpenWriteStream(destination)) diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 553e6b41a..d427f229e 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -686,6 +686,7 @@ +