mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-16 02:18:54 -07:00
add poster dynamic images
This commit is contained in:
parent
527f4887e9
commit
c9c5a93450
@ -126,7 +126,7 @@ namespace MediaBrowser.Server.Implementations.Photos
|
||||
|
||||
protected abstract Task<List<BaseItem>> GetItemsWithImages(IHasImages item);
|
||||
|
||||
private const string Version = "9";
|
||||
private const string Version = "15";
|
||||
protected string GetConfigurationCacheKey(List<BaseItem> items, string itemName)
|
||||
{
|
||||
var parts = Version + "_" + (itemName ?? string.Empty) + "_" +
|
||||
@ -151,7 +151,7 @@ namespace MediaBrowser.Server.Implementations.Photos
|
||||
|
||||
protected Task<Stream> GetPosterCollage(IHasImages primaryItem, List<BaseItem> items)
|
||||
{
|
||||
var stream = new StripCollageBuilder(ApplicationPaths).BuildSquareCollage(GetStripCollageImagePaths(items), 800, 800, true, primaryItem.Name);
|
||||
var stream = new StripCollageBuilder(ApplicationPaths).BuildPosterCollage(GetStripCollageImagePaths(items), 600, 900, true, primaryItem.Name);
|
||||
|
||||
return Task.FromResult(stream);
|
||||
}
|
||||
|
@ -18,6 +18,21 @@ namespace MediaBrowser.Server.Implementations.UserViews
|
||||
_appPaths = appPaths;
|
||||
}
|
||||
|
||||
public Stream BuildPosterCollage(IEnumerable<string> paths, int width, int height, bool renderWithText, string text)
|
||||
{
|
||||
if (renderWithText)
|
||||
{
|
||||
using (var wand = BuildPosterCollageWandWithText(paths, text, width, height))
|
||||
{
|
||||
return DynamicImageHelpers.GetStream(wand, _appPaths);
|
||||
}
|
||||
}
|
||||
using (var wand = BuildPosterCollageWand(paths, width, height))
|
||||
{
|
||||
return DynamicImageHelpers.GetStream(wand, _appPaths);
|
||||
}
|
||||
}
|
||||
|
||||
public Stream BuildSquareCollage(IEnumerable<string> paths, int width, int height, bool renderWithText, string text)
|
||||
{
|
||||
if (renderWithText)
|
||||
@ -27,12 +42,9 @@ namespace MediaBrowser.Server.Implementations.UserViews
|
||||
return DynamicImageHelpers.GetStream(wand, _appPaths);
|
||||
}
|
||||
}
|
||||
else
|
||||
using (var wand = BuildSquareCollageWand(paths, width, height))
|
||||
{
|
||||
using (var wand = BuildSquareCollageWand(paths, width, height))
|
||||
{
|
||||
return DynamicImageHelpers.GetStream(wand, _appPaths);
|
||||
}
|
||||
return DynamicImageHelpers.GetStream(wand, _appPaths);
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,12 +57,9 @@ namespace MediaBrowser.Server.Implementations.UserViews
|
||||
return DynamicImageHelpers.GetStream(wand, _appPaths);
|
||||
}
|
||||
}
|
||||
else
|
||||
using (var wand = BuildThumbCollageWand(paths, width, height))
|
||||
{
|
||||
using (var wand = BuildThumbCollageWand(paths, width, height))
|
||||
{
|
||||
return DynamicImageHelpers.GetStream(wand, _appPaths);
|
||||
}
|
||||
return DynamicImageHelpers.GetStream(wand, _appPaths);
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,6 +153,131 @@ namespace MediaBrowser.Server.Implementations.UserViews
|
||||
}
|
||||
}
|
||||
|
||||
private MagickWand BuildPosterCollageWand(IEnumerable<string> paths, int width, int height)
|
||||
{
|
||||
var inputPaths = ProjectPaths(paths, 3);
|
||||
using (var wandImages = new MagickWand(inputPaths))
|
||||
{
|
||||
var wand = new MagickWand(width, height);
|
||||
wand.OpenImage("gradient:#111111-#111111");
|
||||
using (var draw = new DrawingWand())
|
||||
{
|
||||
var iSlice = Convert.ToInt32(width * .3);
|
||||
int iTrans = Convert.ToInt32(height * .25);
|
||||
int iHeight = Convert.ToInt32(height * .65);
|
||||
var horizontalImagePadding = Convert.ToInt32(width * 0.025);
|
||||
|
||||
foreach (var element in wandImages.ImageList)
|
||||
{
|
||||
int iWidth = (int)Math.Abs(iHeight * element.Width / element.Height);
|
||||
element.Gravity = GravityType.CenterGravity;
|
||||
element.BackgroundColor = ColorName.Black;
|
||||
element.ResizeImage(iWidth, iHeight, FilterTypes.LanczosFilter);
|
||||
int ix = (int)Math.Abs((iWidth - iSlice) / 2);
|
||||
element.CropImage(iSlice, iHeight, ix, 0);
|
||||
|
||||
element.ExtentImage(iSlice, iHeight, 0 - horizontalImagePadding, 0);
|
||||
}
|
||||
|
||||
wandImages.SetFirstIterator();
|
||||
using (var wandList = wandImages.AppendImages())
|
||||
{
|
||||
wandList.CurrentImage.TrimImage(1);
|
||||
using (var mwr = wandList.CloneMagickWand())
|
||||
{
|
||||
mwr.CurrentImage.ResizeImage(wandList.CurrentImage.Width, (wandList.CurrentImage.Height / 2), FilterTypes.LanczosFilter, 1);
|
||||
mwr.CurrentImage.FlipImage();
|
||||
|
||||
mwr.CurrentImage.AlphaChannel = AlphaChannelType.DeactivateAlphaChannel;
|
||||
mwr.CurrentImage.ColorizeImage(ColorName.Black, ColorName.Grey70);
|
||||
|
||||
using (var mwg = new MagickWand(wandList.CurrentImage.Width, iTrans))
|
||||
{
|
||||
mwg.OpenImage("gradient:black-none");
|
||||
var verticalSpacing = Convert.ToInt32(height * 0.01111111111111111111111111111111);
|
||||
mwr.CurrentImage.CompositeImage(mwg, CompositeOperator.CopyOpacityCompositeOp, 0, verticalSpacing);
|
||||
|
||||
wandList.AddImage(mwr);
|
||||
int ex = (int)(wand.CurrentImage.Width - mwg.CurrentImage.Width) / 2;
|
||||
wand.CurrentImage.CompositeImage(wandList.AppendImages(true), CompositeOperator.AtopCompositeOp, ex, Convert.ToInt32(height * .05));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return wand;
|
||||
}
|
||||
}
|
||||
|
||||
private MagickWand BuildPosterCollageWandWithText(IEnumerable<string> paths, string label, int width, int height)
|
||||
{
|
||||
var inputPaths = ProjectPaths(paths, 3);
|
||||
using (var wandImages = new MagickWand(inputPaths))
|
||||
{
|
||||
var wand = new MagickWand(width, height);
|
||||
wand.OpenImage("gradient:#111111-#111111");
|
||||
using (var draw = new DrawingWand())
|
||||
{
|
||||
using (var fcolor = new PixelWand(ColorName.White))
|
||||
{
|
||||
draw.FillColor = fcolor;
|
||||
draw.Font = MontserratLightFont;
|
||||
draw.FontSize = 60;
|
||||
draw.FontWeight = FontWeightType.LightStyle;
|
||||
draw.TextAntialias = true;
|
||||
}
|
||||
|
||||
var fontMetrics = wand.QueryFontMetrics(draw, label);
|
||||
var textContainerY = Convert.ToInt32(height * .165);
|
||||
wand.CurrentImage.AnnotateImage(draw, (width - fontMetrics.TextWidth) / 2, textContainerY, 0.0, label);
|
||||
|
||||
var iSlice = Convert.ToInt32(width * .3);
|
||||
int iTrans = Convert.ToInt32(height * 0.2);
|
||||
int iHeight = Convert.ToInt32(height * 0.46296296296296296296296296296296);
|
||||
var horizontalImagePadding = Convert.ToInt32(width * 0.025);
|
||||
|
||||
foreach (var element in wandImages.ImageList)
|
||||
{
|
||||
int iWidth = (int)Math.Abs(iHeight * element.Width / element.Height);
|
||||
element.Gravity = GravityType.CenterGravity;
|
||||
element.BackgroundColor = new PixelWand("none", 1);
|
||||
element.ResizeImage(iWidth, iHeight, FilterTypes.LanczosFilter);
|
||||
int ix = (int)Math.Abs((iWidth - iSlice) / 2);
|
||||
element.CropImage(iSlice, iHeight, ix, 0);
|
||||
|
||||
element.ExtentImage(iSlice, iHeight, 0 - horizontalImagePadding, 0);
|
||||
}
|
||||
|
||||
wandImages.SetFirstIterator();
|
||||
using (var wandList = wandImages.AppendImages())
|
||||
{
|
||||
wandList.CurrentImage.TrimImage(1);
|
||||
using (var mwr = wandList.CloneMagickWand())
|
||||
{
|
||||
mwr.CurrentImage.ResizeImage(wandList.CurrentImage.Width, (wandList.CurrentImage.Height / 2), FilterTypes.LanczosFilter, 1);
|
||||
mwr.CurrentImage.FlipImage();
|
||||
|
||||
mwr.CurrentImage.AlphaChannel = AlphaChannelType.DeactivateAlphaChannel;
|
||||
mwr.CurrentImage.ColorizeImage(ColorName.Black, ColorName.Grey60);
|
||||
|
||||
using (var mwg = new MagickWand(wandList.CurrentImage.Width, iTrans))
|
||||
{
|
||||
mwg.OpenImage("gradient:black-none");
|
||||
var verticalSpacing = Convert.ToInt32(height * 0.01111111111111111111111111111111);
|
||||
mwr.CurrentImage.CompositeImage(mwg, CompositeOperator.DstInCompositeOp, 0, verticalSpacing);
|
||||
|
||||
wandList.AddImage(mwr);
|
||||
int ex = (int)(wand.CurrentImage.Width - mwg.CurrentImage.Width) / 2;
|
||||
wand.CurrentImage.CompositeImage(wandList.AppendImages(true), CompositeOperator.AtopCompositeOp, ex, Convert.ToInt32(height * 0.26851851851851851851851851851852));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return wand;
|
||||
}
|
||||
}
|
||||
|
||||
private MagickWand BuildThumbCollageWand(IEnumerable<string> paths, int width, int height)
|
||||
{
|
||||
var inputPaths = ProjectPaths(paths, 8);
|
||||
@ -209,9 +343,9 @@ namespace MediaBrowser.Server.Implementations.UserViews
|
||||
wand.OpenImage("gradient:#111111-#111111");
|
||||
using (var draw = new DrawingWand())
|
||||
{
|
||||
var iSlice = Convert.ToInt32(width * 0.2333333334);
|
||||
var iSlice = Convert.ToInt32(width * .225);
|
||||
int iTrans = Convert.ToInt32(height * .25);
|
||||
int iHeight = Convert.ToInt32(height * .65);
|
||||
int iHeight = Convert.ToInt32(height * .63);
|
||||
var horizontalImagePadding = Convert.ToInt32(width * 0.02);
|
||||
|
||||
foreach (var element in wandImages.ImageList)
|
||||
@ -246,7 +380,7 @@ namespace MediaBrowser.Server.Implementations.UserViews
|
||||
|
||||
wandList.AddImage(mwr);
|
||||
int ex = (int)(wand.CurrentImage.Width - mwg.CurrentImage.Width) / 2;
|
||||
wand.CurrentImage.CompositeImage(wandList.AppendImages(true), CompositeOperator.AtopCompositeOp, ex, Convert.ToInt32(height * .05));
|
||||
wand.CurrentImage.CompositeImage(wandList.AppendImages(true), CompositeOperator.AtopCompositeOp, ex, Convert.ToInt32(height * .07));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -278,7 +412,7 @@ namespace MediaBrowser.Server.Implementations.UserViews
|
||||
var textContainerY = Convert.ToInt32(height * .165);
|
||||
wand.CurrentImage.AnnotateImage(draw, (width - fontMetrics.TextWidth) / 2, textContainerY, 0.0, label);
|
||||
|
||||
var iSlice = Convert.ToInt32(width * 0.2333333334);
|
||||
var iSlice = Convert.ToInt32(width * .225);
|
||||
int iTrans = Convert.ToInt32(height * 0.2);
|
||||
int iHeight = Convert.ToInt32(height * 0.46296296296296296296296296296296);
|
||||
var horizontalImagePadding = Convert.ToInt32(width * 0.02);
|
||||
|
@ -202,7 +202,14 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg
|
||||
}
|
||||
}
|
||||
|
||||
throw new ApplicationException("Unable to download required components. Please try again later.");
|
||||
if (downloadinfo.DownloadUrls.Length == 0)
|
||||
{
|
||||
throw new ApplicationException("ffmpeg unvailable. Please install it and start the server with two command line arguments: -ffmpeg \"{PATH}\" and -ffprobe \"{PATH}\"");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ApplicationException("Unable to download required components. Please try again later.");
|
||||
}
|
||||
}
|
||||
|
||||
private void ExtractFFMpeg(FFMpegDownloadInfo downloadinfo, string tempFile, string targetFolder)
|
||||
|
Loading…
Reference in New Issue
Block a user