From 3228f50895d52afb97e985d8223ffc062a75c69a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 2 May 2014 10:49:28 -0400 Subject: fixed user image scaling --- MediaBrowser.Api/Images/ImageService.cs | 43 +++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.Api/Images/ImageService.cs') diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.cs index da21342ac..a5bb291ae 100644 --- a/MediaBrowser.Api/Images/ImageService.cs +++ b/MediaBrowser.Api/Images/ImageService.cs @@ -1,8 +1,7 @@ -using MediaBrowser.Common.Configuration; +using System.Globalization; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Controller.Drawing; -using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Persistence; @@ -48,6 +47,8 @@ namespace MediaBrowser.Api.Images /// The id. [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] public string Id { get; set; } + + public string Params { get; set; } } /// @@ -358,9 +359,47 @@ namespace MediaBrowser.Api.Images _libraryManager.RootFolder : _libraryManager.GetItemById(request.Id); + if (!string.IsNullOrEmpty(request.Params)) + { + ParseOptions(request, request.Params); + } + return GetImage(request, item); } + private readonly CultureInfo _usCulture = new CultureInfo("en-US"); + private void ParseOptions(ImageRequest request, string options) + { + var vals = options.Split(';'); + + for (var i = 0; i < vals.Length; i++) + { + var val = vals[i]; + + if (string.IsNullOrWhiteSpace(val)) + { + continue; + } + + if (i == 0) + { + request.Tag = val; + } + else if (i == 1) + { + request.Format = (ImageOutputFormat)Enum.Parse(typeof(ImageOutputFormat), val, true); + } + else if (i == 2) + { + request.MaxWidth = int.Parse(val, _usCulture); + } + else if (i == 3) + { + request.MaxHeight = int.Parse(val, _usCulture); + } + } + } + /// /// Gets the specified request. /// -- cgit v1.2.3