aboutsummaryrefslogtreecommitdiff
path: root/Emby.Drawing/ImageMagick
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2015-10-26 18:50:19 -0400
committerLuke <luke.pulverenti@gmail.com>2015-10-26 18:50:19 -0400
commit35778ebc02e5931142a1fe31a256b7488a07c5c2 (patch)
treeced0290be8820f5e507b51ca4c5165212b1879d1 /Emby.Drawing/ImageMagick
parentc0dc8d055bfd4d2f58591083beb9e9128357aad6 (diff)
parent8d77308593c3b16b733b0109323770d9dfe7e166 (diff)
Merge pull request #1222 from MediaBrowser/dev
3.0.5768.7
Diffstat (limited to 'Emby.Drawing/ImageMagick')
-rw-r--r--Emby.Drawing/ImageMagick/ImageMagickEncoder.cs46
-rw-r--r--Emby.Drawing/ImageMagick/PlayedIndicatorDrawer.cs28
-rw-r--r--Emby.Drawing/ImageMagick/StripCollageBuilder.cs18
-rw-r--r--Emby.Drawing/ImageMagick/UnplayedCountIndicator.cs8
4 files changed, 68 insertions, 32 deletions
diff --git a/Emby.Drawing/ImageMagick/ImageMagickEncoder.cs b/Emby.Drawing/ImageMagick/ImageMagickEncoder.cs
index 6ff40d1cf2..ed0760ee33 100644
--- a/Emby.Drawing/ImageMagick/ImageMagickEncoder.cs
+++ b/Emby.Drawing/ImageMagick/ImageMagickEncoder.cs
@@ -8,6 +8,7 @@ using MediaBrowser.Model.Logging;
using System;
using System.IO;
using System.Linq;
+using CommonIO;
namespace Emby.Drawing.ImageMagick
{
@@ -16,14 +17,16 @@ namespace Emby.Drawing.ImageMagick
private readonly ILogger _logger;
private readonly IApplicationPaths _appPaths;
private readonly IHttpClient _httpClient;
+ private readonly IFileSystem _fileSystem;
- public ImageMagickEncoder(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient)
+ public ImageMagickEncoder(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IFileSystem fileSystem)
{
_logger = logger;
_appPaths = appPaths;
_httpClient = httpClient;
+ _fileSystem = fileSystem;
- LogImageMagickVersion();
+ LogVersion();
}
public string[] SupportedInputFormats
@@ -64,7 +67,7 @@ namespace Emby.Drawing.ImageMagick
}
}
- private void LogImageMagickVersion()
+ private void LogVersion()
{
_logger.Info("ImageMagick version: " + Wand.VersionString);
TestWebp();
@@ -77,16 +80,16 @@ namespace Emby.Drawing.ImageMagick
try
{
var tmpPath = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".webp");
- Directory.CreateDirectory(Path.GetDirectoryName(tmpPath));
+ _fileSystem.CreateDirectory(Path.GetDirectoryName(tmpPath));
using (var wand = new MagickWand(1, 1, new PixelWand("none", 1)))
{
wand.SaveImage(tmpPath);
}
}
- catch (Exception ex)
+ catch
{
- _logger.ErrorException("Error loading webp: ", ex);
+ //_logger.ErrorException("Error loading webp: ", ex);
_webpAvailable = false;
}
}
@@ -100,6 +103,7 @@ namespace Emby.Drawing.ImageMagick
wand.CurrentImage.TrimImage(10);
wand.SaveImage(outputPath);
}
+ SaveDelay();
}
public ImageSize GetImageSize(string path)
@@ -159,6 +163,7 @@ namespace Emby.Drawing.ImageMagick
}
}
}
+ SaveDelay();
}
/// <summary>
@@ -181,14 +186,14 @@ namespace Emby.Drawing.ImageMagick
{
var currentImageSize = new ImageSize(imageWidth, imageHeight);
- var task = new PlayedIndicatorDrawer(_appPaths, _httpClient).DrawPlayedIndicator(wand, currentImageSize);
+ var task = new PlayedIndicatorDrawer(_appPaths, _httpClient, _fileSystem).DrawPlayedIndicator(wand, currentImageSize);
Task.WaitAll(task);
}
else if (options.UnplayedCount.HasValue)
{
var currentImageSize = new ImageSize(imageWidth, imageHeight);
- new UnplayedCountIndicator(_appPaths).DrawUnplayedCountIndicator(wand, currentImageSize, options.UnplayedCount.Value);
+ new UnplayedCountIndicator(_appPaths, _fileSystem).DrawUnplayedCountIndicator(wand, currentImageSize, options.UnplayedCount.Value);
}
if (options.PercentPlayed > 0)
@@ -209,16 +214,25 @@ namespace Emby.Drawing.ImageMagick
if (ratio >= 1.4)
{
- new StripCollageBuilder(_appPaths).BuildThumbCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text);
+ new StripCollageBuilder(_appPaths, _fileSystem).BuildThumbCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text);
}
else if (ratio >= .9)
{
- new StripCollageBuilder(_appPaths).BuildSquareCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text);
+ new StripCollageBuilder(_appPaths, _fileSystem).BuildSquareCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text);
}
else
{
- new StripCollageBuilder(_appPaths).BuildPosterCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text);
+ new StripCollageBuilder(_appPaths, _fileSystem).BuildPosterCollage(options.InputPaths.ToList(), options.OutputPath, options.Width, options.Height, options.Text);
}
+
+ SaveDelay();
+ }
+
+ private void SaveDelay()
+ {
+ // For some reason the images are not always getting released right away
+ var task = Task.Delay(300);
+ Task.WaitAll(task);
}
public string Name
@@ -240,5 +254,15 @@ namespace Emby.Drawing.ImageMagick
throw new ObjectDisposedException(GetType().Name);
}
}
+
+ public bool SupportsImageCollageCreation
+ {
+ get { return true; }
+ }
+
+ public bool SupportsImageEncoding
+ {
+ get { return true; }
+ }
}
}
diff --git a/Emby.Drawing/ImageMagick/PlayedIndicatorDrawer.cs b/Emby.Drawing/ImageMagick/PlayedIndicatorDrawer.cs
index 1c751de1fd..0870b37670 100644
--- a/Emby.Drawing/ImageMagick/PlayedIndicatorDrawer.cs
+++ b/Emby.Drawing/ImageMagick/PlayedIndicatorDrawer.cs
@@ -5,6 +5,8 @@ using MediaBrowser.Model.Drawing;
using System;
using System.IO;
using System.Threading.Tasks;
+using CommonIO;
+using MediaBrowser.Common.IO;
namespace Emby.Drawing.ImageMagick
{
@@ -14,12 +16,14 @@ namespace Emby.Drawing.ImageMagick
private const int OffsetFromTopRightCorner = 38;
private readonly IApplicationPaths _appPaths;
- private readonly IHttpClient _iHttpClient;
+ private readonly IHttpClient _iHttpClient;
+ private readonly IFileSystem _fileSystem;
- public PlayedIndicatorDrawer(IApplicationPaths appPaths, IHttpClient iHttpClient)
+ public PlayedIndicatorDrawer(IApplicationPaths appPaths, IHttpClient iHttpClient, IFileSystem fileSystem)
{
_appPaths = appPaths;
_iHttpClient = iHttpClient;
+ _fileSystem = fileSystem;
}
public async Task DrawPlayedIndicator(MagickWand wand, ImageSize imageSize)
@@ -38,7 +42,7 @@ namespace Emby.Drawing.ImageMagick
pixel.Opacity = 0;
pixel.Color = "white";
draw.FillColor = pixel;
- draw.Font = await DownloadFont("webdings.ttf", "https://github.com/MediaBrowser/Emby.Resources/raw/master/fonts/webdings.ttf", _appPaths, _iHttpClient).ConfigureAwait(false);
+ draw.Font = await DownloadFont("webdings.ttf", "https://github.com/MediaBrowser/Emby.Resources/raw/master/fonts/webdings.ttf", _appPaths, _iHttpClient, _fileSystem).ConfigureAwait(false);
draw.FontSize = FontSize;
draw.FontStyle = FontStyleType.NormalStyle;
draw.TextAlignment = TextAlignType.CenterAlign;
@@ -52,18 +56,18 @@ namespace Emby.Drawing.ImageMagick
}
}
- internal static string ExtractFont(string name, IApplicationPaths paths)
+ internal static string ExtractFont(string name, IApplicationPaths paths, IFileSystem fileSystem)
{
var filePath = Path.Combine(paths.ProgramDataPath, "fonts", name);
- if (File.Exists(filePath))
+ if (fileSystem.FileExists(filePath))
{
return filePath;
}
var namespacePath = typeof(PlayedIndicatorDrawer).Namespace + ".fonts." + name;
var tempPath = Path.Combine(paths.TempDirectory, Guid.NewGuid().ToString("N") + ".ttf");
- Directory.CreateDirectory(Path.GetDirectoryName(tempPath));
+ fileSystem.CreateDirectory(Path.GetDirectoryName(tempPath));
using (var stream = typeof(PlayedIndicatorDrawer).Assembly.GetManifestResourceStream(namespacePath))
{
@@ -73,11 +77,11 @@ namespace Emby.Drawing.ImageMagick
}
}
- Directory.CreateDirectory(Path.GetDirectoryName(filePath));
+ fileSystem.CreateDirectory(Path.GetDirectoryName(filePath));
try
{
- File.Copy(tempPath, filePath, false);
+ fileSystem.CopyFile(tempPath, filePath, false);
}
catch (IOException)
{
@@ -87,11 +91,11 @@ namespace Emby.Drawing.ImageMagick
return tempPath;
}
- internal static async Task<string> DownloadFont(string name, string url, IApplicationPaths paths, IHttpClient httpClient)
+ internal static async Task<string> DownloadFont(string name, string url, IApplicationPaths paths, IHttpClient httpClient, IFileSystem fileSystem)
{
var filePath = Path.Combine(paths.ProgramDataPath, "fonts", name);
- if (File.Exists(filePath))
+ if (fileSystem.FileExists(filePath))
{
return filePath;
}
@@ -103,11 +107,11 @@ namespace Emby.Drawing.ImageMagick
}).ConfigureAwait(false);
- Directory.CreateDirectory(Path.GetDirectoryName(filePath));
+ fileSystem.CreateDirectory(Path.GetDirectoryName(filePath));
try
{
- File.Copy(tempPath, filePath, false);
+ fileSystem.CopyFile(tempPath, filePath, false);
}
catch (IOException)
{
diff --git a/Emby.Drawing/ImageMagick/StripCollageBuilder.cs b/Emby.Drawing/ImageMagick/StripCollageBuilder.cs
index 7ed0f36e2c..a7e3a155d6 100644
--- a/Emby.Drawing/ImageMagick/StripCollageBuilder.cs
+++ b/Emby.Drawing/ImageMagick/StripCollageBuilder.cs
@@ -2,16 +2,20 @@
using MediaBrowser.Common.Configuration;
using System;
using System.Collections.Generic;
+using CommonIO;
+using MediaBrowser.Common.IO;
namespace Emby.Drawing.ImageMagick
{
public class StripCollageBuilder
{
private readonly IApplicationPaths _appPaths;
+ private readonly IFileSystem _fileSystem;
- public StripCollageBuilder(IApplicationPaths appPaths)
+ public StripCollageBuilder(IApplicationPaths appPaths, IFileSystem fileSystem)
{
_appPaths = appPaths;
+ _fileSystem = fileSystem;
}
public void BuildPosterCollage(List<string> paths, string outputPath, int width, int height, string text)
@@ -145,17 +149,17 @@ namespace Emby.Drawing.ImageMagick
private MagickWand BuildPosterCollageWand(List<string> paths, int width, int height)
{
- var inputPaths = ImageHelpers.ProjectPaths(paths, 4);
+ var inputPaths = ImageHelpers.ProjectPaths(paths, 3);
using (var wandImages = new MagickWand(inputPaths.ToArray()))
{
var wand = new MagickWand(width, height);
wand.OpenImage("gradient:#111111-#111111");
using (var draw = new DrawingWand())
{
- var iSlice = Convert.ToInt32(width * 0.225);
+ var iSlice = Convert.ToInt32(width * 0.3);
int iTrans = Convert.ToInt32(height * .25);
int iHeight = Convert.ToInt32(height * .65);
- var horizontalImagePadding = Convert.ToInt32(width * 0.0275);
+ var horizontalImagePadding = Convert.ToInt32(width * 0.0366);
foreach (var element in wandImages.ImageList)
{
@@ -350,14 +354,14 @@ namespace Emby.Drawing.ImageMagick
private MagickWand BuildSquareCollageWand(List<string> paths, int width, int height)
{
- var inputPaths = ImageHelpers.ProjectPaths(paths, 4);
+ var inputPaths = ImageHelpers.ProjectPaths(paths, 3);
using (var wandImages = new MagickWand(inputPaths.ToArray()))
{
var wand = new MagickWand(width, height);
wand.OpenImage("gradient:#111111-#111111");
using (var draw = new DrawingWand())
{
- var iSlice = Convert.ToInt32(width * .225);
+ var iSlice = Convert.ToInt32(width * .3);
int iTrans = Convert.ToInt32(height * .25);
int iHeight = Convert.ToInt32(height * .63);
var horizontalImagePadding = Convert.ToInt32(width * 0.02);
@@ -490,7 +494,7 @@ namespace Emby.Drawing.ImageMagick
private string MontserratLightFont
{
- get { return PlayedIndicatorDrawer.ExtractFont("MontserratLight.otf", _appPaths); }
+ get { return PlayedIndicatorDrawer.ExtractFont("MontserratLight.otf", _appPaths, _fileSystem); }
}
}
}
diff --git a/Emby.Drawing/ImageMagick/UnplayedCountIndicator.cs b/Emby.Drawing/ImageMagick/UnplayedCountIndicator.cs
index dd25004d66..d3d9c1e7a0 100644
--- a/Emby.Drawing/ImageMagick/UnplayedCountIndicator.cs
+++ b/Emby.Drawing/ImageMagick/UnplayedCountIndicator.cs
@@ -1,7 +1,9 @@
using ImageMagickSharp;
using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.IO;
using MediaBrowser.Model.Drawing;
using System.Globalization;
+using CommonIO;
namespace Emby.Drawing.ImageMagick
{
@@ -10,10 +12,12 @@ namespace Emby.Drawing.ImageMagick
private const int OffsetFromTopRightCorner = 38;
private readonly IApplicationPaths _appPaths;
+ private readonly IFileSystem _fileSystem;
- public UnplayedCountIndicator(IApplicationPaths appPaths)
+ public UnplayedCountIndicator(IApplicationPaths appPaths, IFileSystem fileSystem)
{
_appPaths = appPaths;
+ _fileSystem = fileSystem;
}
public void DrawUnplayedCountIndicator(MagickWand wand, ImageSize imageSize, int count)
@@ -33,7 +37,7 @@ namespace Emby.Drawing.ImageMagick
pixel.Opacity = 0;
pixel.Color = "white";
draw.FillColor = pixel;
- draw.Font = PlayedIndicatorDrawer.ExtractFont("robotoregular.ttf", _appPaths);
+ draw.Font = PlayedIndicatorDrawer.ExtractFont("robotoregular.ttf", _appPaths, _fileSystem);
draw.FontStyle = FontStyleType.NormalStyle;
draw.TextAlignment = TextAlignType.CenterAlign;
draw.FontWeight = FontWeightType.RegularStyle;