mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-21 09:34:44 +01:00
fixes #518 - Add api param for watched indicator on images
This commit is contained in:
@@ -109,7 +109,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||
|
||||
var quality = options.Quality ?? 90;
|
||||
|
||||
var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, options.OutputFormat);
|
||||
var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, options.OutputFormat, options.Indicator);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -175,6 +175,8 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||
|
||||
thumbnailGraph.DrawImage(originalImage, 0, 0, newWidth, newHeight);
|
||||
|
||||
DrawIndicator(thumbnailGraph, newWidth, newHeight, options.Indicator);
|
||||
|
||||
var outputFormat = GetOutputFormat(originalImage, options.OutputFormat);
|
||||
|
||||
using (var outputMemoryStream = new MemoryStream())
|
||||
@@ -204,6 +206,20 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||
}
|
||||
}
|
||||
|
||||
private WatchedIndicatorDrawer _watchedDrawer;
|
||||
|
||||
private void DrawIndicator(Graphics graphics, int imageWidth, int imageHeight, ImageOverlay indicator)
|
||||
{
|
||||
if (indicator == ImageOverlay.Watched)
|
||||
{
|
||||
_watchedDrawer = _watchedDrawer ?? (_watchedDrawer = new WatchedIndicatorDrawer());
|
||||
|
||||
var currentImageSize = new Size(imageWidth, imageHeight);
|
||||
|
||||
_watchedDrawer.Process(graphics, currentImageSize);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the output format.
|
||||
/// </summary>
|
||||
@@ -322,12 +338,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||
/// <summary>
|
||||
/// Gets the cache file path based on a set of parameters
|
||||
/// </summary>
|
||||
/// <param name="originalPath">The path to the original image file</param>
|
||||
/// <param name="outputSize">The size to output the image in</param>
|
||||
/// <param name="quality">Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.</param>
|
||||
/// <param name="dateModified">The last modified date of the image</param>
|
||||
/// <returns>System.String.</returns>
|
||||
private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageOutputFormat format)
|
||||
private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageOutputFormat format, ImageOverlay overlay)
|
||||
{
|
||||
var filename = originalPath;
|
||||
|
||||
@@ -344,6 +355,11 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||
filename += "format=" + format;
|
||||
}
|
||||
|
||||
if (overlay != ImageOverlay.None)
|
||||
{
|
||||
filename += "overlay=" + overlay;
|
||||
}
|
||||
|
||||
return GetCachePath(_resizedImageCachePath, filename, Path.GetExtension(originalPath));
|
||||
}
|
||||
|
||||
@@ -506,7 +522,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
|
||||
return string.Join("|", cacheKeys.ToArray()).GetMD5();
|
||||
}
|
||||
|
||||
private async Task<Tuple<string,DateTime>> GetEnhancedImage(string originalImagePath, DateTime dateModified, BaseItem item,
|
||||
private async Task<Tuple<string, DateTime>> GetEnhancedImage(string originalImagePath, DateTime dateModified, BaseItem item,
|
||||
ImageType imageType, int imageIndex,
|
||||
List<IImageEnhancer> enhancers)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Drawing
|
||||
{
|
||||
public class WatchedIndicatorDrawer
|
||||
{
|
||||
private const int IndicatorHeight = 50;
|
||||
private const int FontSize = 50;
|
||||
|
||||
public void Process(Graphics graphics, Size imageSize)
|
||||
{
|
||||
var x = imageSize.Width - IndicatorHeight;
|
||||
|
||||
using (var backdroundBrush = new SolidBrush(Color.FromArgb(225, 204, 51, 51)))
|
||||
{
|
||||
graphics.FillRectangle(backdroundBrush, x, 0, IndicatorHeight, IndicatorHeight);
|
||||
|
||||
const string text = "a";
|
||||
|
||||
x = imageSize.Width - 55;
|
||||
|
||||
using (var font = new Font("Webdings", FontSize, FontStyle.Regular, GraphicsUnit.Pixel))
|
||||
{
|
||||
using (var fontBrush = new SolidBrush(Color.White))
|
||||
{
|
||||
graphics.DrawString(text, font, fontBrush, x, -2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,6 +114,7 @@
|
||||
<Compile Include="BdInfo\BdInfoExaminer.cs" />
|
||||
<Compile Include="Configuration\ServerConfigurationManager.cs" />
|
||||
<Compile Include="Drawing\ImageHeader.cs" />
|
||||
<Compile Include="Drawing\WatchedIndicatorDrawer.cs" />
|
||||
<Compile Include="Dto\DtoService.cs" />
|
||||
<Compile Include="EntryPoints\LibraryChangedNotifier.cs" />
|
||||
<Compile Include="EntryPoints\LoadRegistrations.cs" />
|
||||
|
||||
Reference in New Issue
Block a user