diff --git a/MediaBrowser.Controller/Drawing/ImageExtensions.cs b/MediaBrowser.Controller/Drawing/ImageExtensions.cs
index c7e1968e7b..2511659c3f 100644
--- a/MediaBrowser.Controller/Drawing/ImageExtensions.cs
+++ b/MediaBrowser.Controller/Drawing/ImageExtensions.cs
@@ -71,39 +71,6 @@ namespace MediaBrowser.Controller.Drawing
return Encoders.Length == 0 ? null : Encoders[0];
}
- ///
- /// Determines whether [is pixel format supported by graphics object] [the specified format].
- ///
- /// The format.
- /// true if [is pixel format supported by graphics object] [the specified format]; otherwise, false.
- public static bool IsPixelFormatSupportedByGraphicsObject(PixelFormat format)
- {
- // http://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage.aspx
-
- if ((format & PixelFormat.Indexed) == PixelFormat.Indexed)
- {
- return false;
- }
- if ((format & PixelFormat.Undefined) == PixelFormat.Undefined)
- {
- return false;
- }
- if ((format & PixelFormat.DontCare) == PixelFormat.DontCare)
- {
- return false;
- }
- if ((format & PixelFormat.Format16bppArgb1555) == PixelFormat.Format16bppArgb1555)
- {
- return false;
- }
- if ((format & PixelFormat.Format16bppGrayScale) == PixelFormat.Format16bppGrayScale)
- {
- return false;
- }
-
- return true;
- }
-
///
/// Crops an image by removing whitespace and transparency from the edges
///
diff --git a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
index 803b4389f9..e66899efaa 100644
--- a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
+++ b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Common.Extensions;
+using Imazen.WebP;
+using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Drawing;
@@ -210,7 +211,12 @@ namespace MediaBrowser.Server.Implementations.Drawing
var newHeight = Convert.ToInt32(newSize.Height);
// Graphics.FromImage will throw an exception if the PixelFormat is Indexed, so we need to handle that here
- using (var thumbnail = new Bitmap(newWidth, newHeight, PixelFormat.Format32bppPArgb))
+ // Also, Webp only supports Format32bppArgb and Format32bppRgb
+ var pixelFormat = options.OutputFormat == ImageOutputFormat.Webp
+ ? PixelFormat.Format32bppArgb
+ : PixelFormat.Format32bppPArgb;
+
+ using (var thumbnail = new Bitmap(newWidth, newHeight, pixelFormat))
{
// Mono throw an exeception if assign 0 to SetResolution
if (originalImage.HorizontalResolution > 0 && originalImage.VerticalResolution > 0)
@@ -242,8 +248,15 @@ namespace MediaBrowser.Server.Implementations.Drawing
// Save to the cache location
using (var cacheFileStream = _fileSystem.GetFileStream(cacheFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, false))
{
- // Save to the memory stream
- thumbnail.Save(outputFormat, cacheFileStream, quality);
+ if (options.OutputFormat == ImageOutputFormat.Webp)
+ {
+ new SimpleEncoder().Encode(thumbnail, cacheFileStream, quality, false);
+ }
+ else
+ {
+ // Save to the memory stream
+ thumbnail.Save(outputFormat, cacheFileStream, quality);
+ }
}
return cacheFilePath;
@@ -260,31 +273,6 @@ namespace MediaBrowser.Server.Implementations.Drawing
}
}
- ///
- /// Caches the resized image.
- ///
- /// The cache file path.
- /// The bytes.
- /// Task.
- private async Task CacheResizedImage(string cacheFilePath, byte[] bytes)
- {
- try
- {
- Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
-
- // Save to the cache location
- using (var cacheFileStream = _fileSystem.GetFileStream(cacheFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
- {
- // Save to the filestream
- await cacheFileStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
- }
- }
- catch (Exception ex)
- {
- _logger.ErrorException("Error writing to image cache file {0}", ex, cacheFilePath);
- }
- }
-
///
/// Sets the color of the background.
///
diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
index dba5baa12f..e8dd54f16e 100644
--- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
+++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
@@ -45,6 +45,10 @@
v4.5
+
+ False
+ ..\ThirdParty\libwebp\Imazen.WebP.dll
+
False
..\packages\Mono.Nat.1.2.21.0\lib\net40\Mono.Nat.dll
@@ -52,9 +56,6 @@
..\packages\morelinq.1.0.16006\lib\net35\MoreLinq.dll
-
- ..\ThirdParty\Nowin\Nowin.dll
-
..\ThirdParty\ServiceStack\ServiceStack.Api.Swagger.dll
@@ -392,6 +393,10 @@
+
+ libwebp.dll
+ PreserveNewest
+
swagger-ui\css\highlight.default.css
PreserveNewest
diff --git a/MediaBrowser.Server.Mono/Imazen.WebP.config b/MediaBrowser.Server.Mono/Imazen.WebP.config
new file mode 100644
index 0000000000..34d8c73c11
--- /dev/null
+++ b/MediaBrowser.Server.Mono/Imazen.WebP.config
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj
index 5d2db29104..a778809d2c 100644
--- a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj
+++ b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj
@@ -145,6 +145,14 @@
+
+ libwebp\linux\lib\libwebp.so
+ PreserveNewest
+
+
+ libwebp\linux\lib64\libwebp.so
+ PreserveNewest
+
sqlite3.dll
PreserveNewest
@@ -165,5 +173,9 @@
System.Data.SQLite.dll.config
PreserveNewest
+
+ Imazen.WebP.dll.config
+ PreserveNewest
+
\ No newline at end of file