mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-18 06:53:07 +03:00
complete gdi fallback
This commit is contained in:
@@ -6,7 +6,6 @@ using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Playlists;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Drawing;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -79,56 +78,23 @@ namespace MediaBrowser.Server.Implementations.Photos
|
||||
string cacheKey,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var stream = CreateImageAsync(item, itemsWithImages, imageType, 0);
|
||||
var outputPath = Path.Combine(ApplicationPaths.TempDirectory, Guid.NewGuid() + ".png");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
|
||||
var imageCreated = CreateImage(item, itemsWithImages, outputPath, imageType, 0);
|
||||
|
||||
if (stream == null)
|
||||
if (!imageCreated)
|
||||
{
|
||||
return ItemUpdateType.None;
|
||||
}
|
||||
|
||||
if (stream is MemoryStream)
|
||||
{
|
||||
using (stream)
|
||||
{
|
||||
stream.Position = 0;
|
||||
|
||||
await ProviderManager.SaveImage(item, stream, "image/png", imageType, null, cacheKey, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
await stream.CopyToAsync(ms).ConfigureAwait(false);
|
||||
|
||||
ms.Position = 0;
|
||||
|
||||
await ProviderManager.SaveImage(item, ms, "image/png", imageType, null, cacheKey, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
await ProviderManager.SaveImage(item, outputPath, "image/png", imageType, null, cacheKey, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return ItemUpdateType.ImageUpdate;
|
||||
}
|
||||
|
||||
public async Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken)
|
||||
{
|
||||
var items = await GetItemsWithImages(item).ConfigureAwait(false);
|
||||
var cacheKey = GetConfigurationCacheKey(items, item.Name);
|
||||
|
||||
var result = CreateImageAsync(item, items, type, 0);
|
||||
|
||||
return new DynamicImageResponse
|
||||
{
|
||||
HasImage = result != null,
|
||||
Stream = result,
|
||||
InternalCacheKey = cacheKey,
|
||||
Format = ImageFormat.Png
|
||||
};
|
||||
}
|
||||
|
||||
protected abstract Task<List<BaseItem>> GetItemsWithImages(IHasImages item);
|
||||
|
||||
private const string Version = "20";
|
||||
private const string Version = "27";
|
||||
protected string GetConfigurationCacheKey(List<BaseItem> items, string itemName)
|
||||
{
|
||||
var parts = Version + "_" + (itemName ?? string.Empty) + "_" +
|
||||
@@ -137,39 +103,35 @@ namespace MediaBrowser.Server.Implementations.Photos
|
||||
return parts.GetMD5().ToString("N");
|
||||
}
|
||||
|
||||
protected Stream GetThumbCollage(IHasImages primaryItem, List<BaseItem> items)
|
||||
protected void CreateThumbCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath)
|
||||
{
|
||||
return GetThumbCollage(primaryItem, items, 960, 540, true, primaryItem.Name);
|
||||
CreateCollage(primaryItem, items, outputPath, 960, 540, true, primaryItem.Name);
|
||||
}
|
||||
|
||||
protected virtual IEnumerable<String> GetStripCollageImagePaths(IHasImages primaryItem, IEnumerable<BaseItem> items)
|
||||
protected virtual IEnumerable<string> GetStripCollageImagePaths(IHasImages primaryItem, IEnumerable<BaseItem> items)
|
||||
{
|
||||
return items
|
||||
.Select(i => i.GetImagePath(ImageType.Primary) ?? i.GetImagePath(ImageType.Thumb))
|
||||
.Where(i => !string.IsNullOrWhiteSpace(i));
|
||||
}
|
||||
|
||||
protected Stream GetPosterCollage(IHasImages primaryItem, List<BaseItem> items)
|
||||
protected void CreatePosterCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath)
|
||||
{
|
||||
var path = CreateCollage(primaryItem, items, 600, 900, true, primaryItem.Name);
|
||||
return FileSystem.GetFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
CreateCollage(primaryItem, items, outputPath, 600, 900, true, primaryItem.Name);
|
||||
}
|
||||
|
||||
protected Stream GetSquareCollage(IHasImages primaryItem, List<BaseItem> items)
|
||||
protected void CreateSquareCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath)
|
||||
{
|
||||
var path = CreateCollage(primaryItem, items, 800, 800, true, primaryItem.Name);
|
||||
return FileSystem.GetFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
CreateCollage(primaryItem, items, outputPath, 800, 800, true, primaryItem.Name);
|
||||
}
|
||||
|
||||
protected Stream GetThumbCollage(IHasImages primaryItem, List<BaseItem> items, int width, int height, bool drawText, string text)
|
||||
protected void CreateThumbCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath, int width, int height, bool drawText, string text)
|
||||
{
|
||||
var path = CreateCollage(primaryItem, items, width, height, drawText, text);
|
||||
return FileSystem.GetFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
CreateCollage(primaryItem, items, outputPath, width, height, drawText, text);
|
||||
}
|
||||
|
||||
private string CreateCollage(IHasImages primaryItem, List<BaseItem> items, int width, int height, bool drawText, string text)
|
||||
private void CreateCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath, int width, int height, bool drawText, string text)
|
||||
{
|
||||
var outputPath = Path.Combine(ApplicationPaths.TempDirectory, Guid.NewGuid() + ".png");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
|
||||
|
||||
var options = new ImageCollageOptions
|
||||
@@ -182,8 +144,6 @@ namespace MediaBrowser.Server.Implementations.Photos
|
||||
};
|
||||
|
||||
ImageProcessor.CreateImageCollage(options);
|
||||
|
||||
return outputPath;
|
||||
}
|
||||
|
||||
public string Name
|
||||
@@ -191,26 +151,35 @@ namespace MediaBrowser.Server.Implementations.Photos
|
||||
get { return "Dynamic Image Provider"; }
|
||||
}
|
||||
|
||||
protected virtual Stream CreateImageAsync(IHasImages item,
|
||||
protected virtual bool CreateImage(IHasImages item,
|
||||
List<BaseItem> itemsWithImages,
|
||||
string outputPath,
|
||||
ImageType imageType,
|
||||
int imageIndex)
|
||||
{
|
||||
if (itemsWithImages.Count == 0)
|
||||
{
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (imageType == ImageType.Thumb)
|
||||
{
|
||||
return GetThumbCollage(item, itemsWithImages);
|
||||
CreateThumbCollage(item, itemsWithImages, outputPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (imageType == ImageType.Primary)
|
||||
{
|
||||
return item is PhotoAlbum || item is Playlist ?
|
||||
GetSquareCollage(item, itemsWithImages) :
|
||||
GetPosterCollage(item, itemsWithImages);
|
||||
if (item is PhotoAlbum || item is Playlist)
|
||||
{
|
||||
CreateSquareCollage(item, itemsWithImages, outputPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
CreatePosterCollage(item, itemsWithImages, outputPath);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
throw new ArgumentException("Unexpected image type");
|
||||
|
||||
Reference in New Issue
Block a user