private string GetMimeType(ImageOutputFormat format, string path) { if (format == ImageOutputFormat.Bmp) { return(Common.Net.MimeTypes.GetMimeType("i.bmp")); } if (format == ImageOutputFormat.Gif) { return(Common.Net.MimeTypes.GetMimeType("i.gif")); } if (format == ImageOutputFormat.Jpg) { return(Common.Net.MimeTypes.GetMimeType("i.jpg")); } if (format == ImageOutputFormat.Png) { return(Common.Net.MimeTypes.GetMimeType("i.png")); } if (format == ImageOutputFormat.Webp) { return(Common.Net.MimeTypes.GetMimeType("i.webp")); } return(Common.Net.MimeTypes.GetMimeType(path)); }
private async Task <object> GetImageResult(IHasImages item, ImageRequest request, ItemImageInfo image, ImageOutputFormat format, List <IImageEnhancer> enhancers, string contentType, TimeSpan?cacheDuration, IDictionary <string, string> headers, bool isHeadRequest) { var cropwhitespace = request.Type == ImageType.Logo || request.Type == ImageType.Art; if (request.CropWhitespace.HasValue) { cropwhitespace = request.CropWhitespace.Value; } var options = new ImageProcessingOptions { CropWhiteSpace = cropwhitespace, Enhancers = enhancers, Height = request.Height, ImageIndex = request.Index ?? 0, Image = image, Item = item, MaxHeight = request.MaxHeight, MaxWidth = request.MaxWidth, Quality = request.Quality, Width = request.Width, AddPlayedIndicator = request.AddPlayedIndicator, PercentPlayed = request.PercentPlayed ?? 0, UnplayedCount = request.UnplayedCount, BackgroundColor = request.BackgroundColor, OutputFormat = format }; var file = await _imageProcessor.ProcessImage(options).ConfigureAwait(false); return(ResultFactory.GetStaticFileResult(Request, new StaticFileResultOptions { CacheDuration = cacheDuration, ResponseHeaders = headers, ContentType = contentType, IsHeadRequest = isHeadRequest, Path = file })); }
/// <summary> /// Gets the output format. /// </summary> /// <param name="image">The image.</param> /// <param name="outputFormat">The output format.</param> /// <returns>ImageFormat.</returns> private System.Drawing.Imaging.ImageFormat GetOutputFormat(Image image, ImageOutputFormat outputFormat) { switch (outputFormat) { case ImageOutputFormat.Bmp: return(System.Drawing.Imaging.ImageFormat.Bmp); case ImageOutputFormat.Gif: return(System.Drawing.Imaging.ImageFormat.Gif); case ImageOutputFormat.Jpg: return(System.Drawing.Imaging.ImageFormat.Jpeg); case ImageOutputFormat.Png: return(System.Drawing.Imaging.ImageFormat.Png); default: return(image.RawFormat); } }
/// <summary> /// Gets the cache file path based on a set of parameters /// </summary> private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageOutputFormat format, bool addPlayedIndicator, double?percentPlayed, int?unwatchedCount, string backgroundColor) { var filename = originalPath; filename += "width=" + outputSize.Width; filename += "height=" + outputSize.Height; filename += "quality=" + quality; filename += "datemodified=" + dateModified.Ticks; if (format != ImageOutputFormat.Original) { filename += "f=" + format; } var hasIndicator = false; if (addPlayedIndicator) { filename += "pl=true"; hasIndicator = true; } if (percentPlayed.HasValue) { filename += "p=" + percentPlayed.Value; hasIndicator = true; } if (unwatchedCount.HasValue) { filename += "p=" + unwatchedCount.Value; hasIndicator = true; } if (hasIndicator) { filename += "iv=" + IndicatorVersion; } if (!string.IsNullOrEmpty(backgroundColor)) { filename += "b=" + backgroundColor; } return(GetCachePath(ResizedImageCachePath, filename, Path.GetExtension(originalPath))); }
/// <summary> /// Gets the cache file path based on a set of parameters /// </summary> private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageOutputFormat format, bool addPlayedIndicator, double? percentPlayed, int? unwatchedCount, string backgroundColor) { var filename = originalPath; filename += "width=" + outputSize.Width; filename += "height=" + outputSize.Height; filename += "quality=" + quality; filename += "datemodified=" + dateModified.Ticks; if (format != ImageOutputFormat.Original) { filename += "f=" + format; } var hasIndicator = false; if (addPlayedIndicator) { filename += "pl=true"; hasIndicator = true; } if (percentPlayed.HasValue) { filename += "p=" + percentPlayed.Value; hasIndicator = true; } if (unwatchedCount.HasValue) { filename += "p=" + unwatchedCount.Value; hasIndicator = true; } if (hasIndicator) { filename += "iv=" + IndicatorVersion; } if (!string.IsNullOrEmpty(backgroundColor)) { filename += "b=" + backgroundColor; } return GetCachePath(ResizedImageCachePath, filename, Path.GetExtension(originalPath)); }
/// <summary> /// Gets the output format. /// </summary> /// <param name="image">The image.</param> /// <param name="outputFormat">The output format.</param> /// <returns>ImageFormat.</returns> private System.Drawing.Imaging.ImageFormat GetOutputFormat(Image image, ImageOutputFormat outputFormat) { switch (outputFormat) { case ImageOutputFormat.Bmp: return System.Drawing.Imaging.ImageFormat.Bmp; case ImageOutputFormat.Gif: return System.Drawing.Imaging.ImageFormat.Gif; case ImageOutputFormat.Jpg: return System.Drawing.Imaging.ImageFormat.Jpeg; case ImageOutputFormat.Png: return System.Drawing.Imaging.ImageFormat.Png; default: return image.RawFormat; } }
/// <summary> /// Gets the cache file path based on a set of parameters /// </summary> private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageOutputFormat format, ImageOverlay? overlay, int percentPlayed, string backgroundColor) { var filename = originalPath; filename += "width=" + outputSize.Width; filename += "height=" + outputSize.Height; filename += "quality=" + quality; filename += "datemodified=" + dateModified.Ticks; if (format != ImageOutputFormat.Original) { filename += "f=" + format; } if (overlay.HasValue) { filename += "o=" + overlay.Value; filename += "p=" + percentPlayed; } if (!string.IsNullOrEmpty(backgroundColor)) { filename += "b=" + backgroundColor; } return GetCachePath(_resizedImageCachePath, filename, Path.GetExtension(originalPath)); }