fixes #324 - Server to return non-cropped images to clients

This commit is contained in:
Luke Pulverenti
2013-06-04 21:19:25 -04:00
parent 25cc19a10b
commit b010faa85b
5 changed files with 26 additions and 13 deletions

View File

@@ -45,6 +45,9 @@ namespace MediaBrowser.Api.Images
/// <value>The tag.</value>
[ApiMember(Name = "Tag", Description = "Optional. Supply the cache tag from the item object to receive strong caching headers.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string Tag { get; set; }
[ApiMember(Name = "CropWhitespace", Description = "Specify if whitespace should be cropped out of the image. True/False. If unspecified, whitespace will be cropped from logos and clear art.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public bool? CropWhitespace { get; set; }
}
/// <summary>

View File

@@ -691,11 +691,14 @@ namespace MediaBrowser.Api.Images
cacheDuration = TimeSpan.FromDays(365);
}
// Avoid implicitly captured closure
var currentItem = item;
var currentRequest = request;
return ToCachedResult(cacheGuid, originalFileImageDateModified, cacheDuration, () => new ImageWriter
{
Item = item,
Request = request,
CropWhiteSpace = request.Type == ImageType.Logo || request.Type == ImageType.Art,
Item = currentItem,
Request = currentRequest,
OriginalImageDateModified = originalFileImageDateModified,
Enhancers = supportedImageEnhancers

View File

@@ -1,6 +1,7 @@
using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using ServiceStack.Service;
using ServiceStack.ServiceHost;
using System;
@@ -28,11 +29,6 @@ namespace MediaBrowser.Api.Images
/// <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;
@@ -68,7 +64,14 @@ namespace MediaBrowser.Api.Images
/// <returns>Task.</returns>
private Task WriteToAsync(Stream responseStream)
{
return Kernel.Instance.ImageManager.ProcessImage(Item, Request.Type, Request.Index ?? 0, CropWhiteSpace,
var cropwhitespace = Request.Type == ImageType.Logo || Request.Type == ImageType.Art;
if (Request.CropWhitespace.HasValue)
{
cropwhitespace = Request.CropWhitespace.Value;
}
return Kernel.Instance.ImageManager.ProcessImage(Item, Request.Type, Request.Index ?? 0, cropwhitespace,
OriginalImageDateModified, responseStream, Request.Width, Request.Height, Request.MaxWidth,
Request.MaxHeight, Request.Quality, Enhancers);
}