aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2015-03-17 12:47:56 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2015-03-17 12:47:56 -0400
commit44d0e30e9de8d2eef957eca1f97ee3fd5aa71810 (patch)
treeda77ba2499f9654a7413c912a0c6b41f76d64a0e
parentd9d295251cb7ff95173e81db55408adc8de17eab (diff)
perform webp test at startup
-rw-r--r--MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs54
1 files changed, 45 insertions, 9 deletions
diff --git a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
index cb6058f3f..79e5a0cf0 100644
--- a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
+++ b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
@@ -130,7 +130,44 @@ namespace MediaBrowser.Server.Implementations.Drawing
public ImageFormat[] GetSupportedImageOutputFormats()
{
- return new[] { ImageFormat.Webp, ImageFormat.Gif, ImageFormat.Jpg, ImageFormat.Png };
+ if (_webpAvailable)
+ {
+ return new[] { ImageFormat.Webp, ImageFormat.Gif, ImageFormat.Jpg, ImageFormat.Png };
+ }
+ return new[] { ImageFormat.Gif, ImageFormat.Jpg, ImageFormat.Png };
+ }
+
+ private bool _webpAvailable = true;
+ private void TestWebp()
+ {
+ try
+ {
+ var tmpPath = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".webp");
+ Directory.CreateDirectory(Path.GetDirectoryName(tmpPath));
+
+ using (var wand = new MagickWand(1, 1, new PixelWand("none", 1)))
+ {
+ wand.SaveImage(tmpPath);
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error loading webp: ", ex);
+ _webpAvailable = false;
+ }
+ }
+
+ private void LogImageMagickVersionVersion()
+ {
+ try
+ {
+ _logger.Info("ImageMagick version: " + Wand.VersionString);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error loading ImageMagick: ", ex);
+ }
+ TestWebp();
}
public async Task<string> ProcessImage(ImageProcessingOptions options)
@@ -179,7 +216,8 @@ namespace MediaBrowser.Server.Implementations.Drawing
var quality = options.Quality ?? 90;
- var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, options.OutputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.UnplayedCount, options.BackgroundColor);
+ var outputFormat = GetOutputFormat(options.OutputFormat);
+ var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, outputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.UnplayedCount, options.BackgroundColor);
var semaphore = GetLock(cacheFilePath);
@@ -250,16 +288,14 @@ namespace MediaBrowser.Server.Implementations.Drawing
}
}
- private void LogImageMagickVersionVersion()
+ private ImageFormat GetOutputFormat(ImageFormat requestedFormat)
{
- try
- {
- _logger.Info("ImageMagick version: " + Wand.VersionString);
- }
- catch (Exception ex)
+ if (requestedFormat == ImageFormat.Webp && !_webpAvailable)
{
- _logger.ErrorException("Error loading ImageMagick: ", ex);
+ return ImageFormat.Png;
}
+
+ return requestedFormat;
}
/// <summary>