perform webp test at startup

pull/702/head
Luke Pulverenti 10 years ago
parent d9d295251c
commit 44d0e30e9d

@ -129,9 +129,46 @@ namespace MediaBrowser.Server.Implementations.Drawing
}
public ImageFormat[] GetSupportedImageOutputFormats()
{
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()
{
try
private ImageFormat GetOutputFormat(ImageFormat requestedFormat)
{
_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>

Loading…
Cancel
Save