aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/Images/ImageWriter.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Api/Images/ImageWriter.cs')
-rw-r--r--MediaBrowser.Api/Images/ImageWriter.cs80
1 files changed, 80 insertions, 0 deletions
diff --git a/MediaBrowser.Api/Images/ImageWriter.cs b/MediaBrowser.Api/Images/ImageWriter.cs
new file mode 100644
index 000000000..22c851056
--- /dev/null
+++ b/MediaBrowser.Api/Images/ImageWriter.cs
@@ -0,0 +1,80 @@
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Entities;
+using ServiceStack.Service;
+using ServiceStack.ServiceHost;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.Images
+{
+ /// <summary>
+ /// Class ImageWriter
+ /// </summary>
+ public class ImageWriter : IStreamWriter, IHasOptions
+ {
+ /// <summary>
+ /// Gets or sets the request.
+ /// </summary>
+ /// <value>The request.</value>
+ public ImageRequest Request { get; set; }
+ /// <summary>
+ /// Gets or sets the item.
+ /// </summary>
+ /// <value>The item.</value>
+ public BaseItem Item { get; set; }
+ /// <summary>
+ /// Gets or sets a value indicating whether [crop white space].
+ /// </summary>
+ /// <value><c>true</c> if [crop white space]; otherwise, <c>false</c>.</value>
+ public bool CropWhiteSpace { get; set; }
+ /// <summary>
+ /// The original image date modified
+ /// </summary>
+ public DateTime OriginalImageDateModified;
+ /// <summary>
+ /// Gets or sets the type of the content.
+ /// </summary>
+ /// <value>The type of the content.</value>
+ public string ContentType { get; set; }
+
+ /// <summary>
+ /// Writes to.
+ /// </summary>
+ /// <param name="responseStream">The response stream.</param>
+ public void WriteTo(Stream responseStream)
+ {
+ Options["Content-Type"] = ContentType;
+
+ var task = WriteToAsync(responseStream);
+
+ Task.WaitAll(task);
+ }
+
+ /// <summary>
+ /// Writes to async.
+ /// </summary>
+ /// <param name="responseStream">The response stream.</param>
+ /// <returns>Task.</returns>
+ private Task WriteToAsync(Stream responseStream)
+ {
+ return Kernel.Instance.ImageManager.ProcessImage(Item, Request.Type, Request.Index ?? 0, CropWhiteSpace,
+ OriginalImageDateModified, responseStream, Request.Width, Request.Height, Request.MaxWidth,
+ Request.MaxHeight, Request.Quality);
+ }
+
+ /// <summary>
+ /// The _options
+ /// </summary>
+ private readonly IDictionary<string, string> _options = new Dictionary<string, string> { };
+ /// <summary>
+ /// Gets the options.
+ /// </summary>
+ /// <value>The options.</value>
+ public IDictionary<string, string> Options
+ {
+ get { return _options; }
+ }
+ }
+}