v0.7.8 - New Filtering System (#2260)
Co-authored-by: JeanPaulDOT <jp.houssier@gmail.com> Co-authored-by: Francois Wilhelmy <ice_mouton@hotmail.com> Co-authored-by: Gazy Mahomar <gmahomarf@gmail.com> Co-authored-by: Stijn <stijn.biemans@gmail.com> Co-authored-by: 無情天 <kofzhanganguo@126.com> Co-authored-by: Havokdan <havokdan@yahoo.com.br> Co-authored-by: Andre <andruecha32@gmail.com> Co-authored-by: Mateusz <mateuszvx8.96@gmail.com> Co-authored-by: Antonio Sanchez Castellón <angelfx19@gmail.com> Co-authored-by: Duarte Silva <smallflake@protonmail.com> Co-authored-by: LeeWan1210 <dldhks456@live.com> Co-authored-by: aleixcox <18121624@qq.com> Co-authored-by: Tomas Battistini <tomas.battistini@gmail.com> Co-authored-by: mareczek82 <marek.posiadala@gmail.com> Co-authored-by: Hans Kalisvaart <hans.kalisvaart@gmail.com> Co-authored-by: majora2007 <kavitareader@gmail.com> Co-authored-by: afermar <adrian.fm@protonmail.com> Co-authored-by: oxygen44k <iiccpp@outlook.com> Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: Hadrien b <hadrien.1997@gmail.com> Co-authored-by: Robbie Davis <robbie@therobbiedavis.com> Co-authored-by: Andre Smith <Hobogrammer@users.noreply.github.com> Co-authored-by: Safu Wan <safu@yahoo.com> Co-authored-by: sibeck <sibeck.clown@gmail.com> Co-authored-by: Florestano Pepe <florestano.pepe@gmail.com> Co-authored-by: 书签 <shuqian.emu@gmail.com> Co-authored-by: Stéphane Dupont <aleistor@gmail.com> Co-authored-by: gallegonovato <fran-carro@hotmail.es> Co-authored-by: AlienHack <the4got10@windowslive.com> Co-authored-by: 周書丞 <tmrsm_chan@hotmail.com> Co-authored-by: Andre Smith <andrepsmithjr@gmail.com> Co-authored-by: xe1st <dnzkckali@gmail.com> Co-authored-by: Jiří Heger <jiri.heger@gmail.com> Co-authored-by: DR <weblate-kavita.snowflake668@slmail.me> Co-authored-by: Mathieu Ares <matguitarist@gmail.com> Co-authored-by: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Co-authored-by: Gazy Mahomar <gmahomarf@users.noreply.github.com> Co-authored-by: Elias Jakob <elias.jakob100@gmail.com> Co-authored-by: Christian Zanon <chri8431@libero.it> Co-authored-by: Eryk Michalak <gnu.ewm@protonmail.com> Co-authored-by: Hoshino0881118 <hoshino0881118@gmail.com>
This commit is contained in:
parent
bdaadbecfc
commit
979508047c
221 changed files with 23403 additions and 6863 deletions
|
|
@ -21,7 +21,7 @@ namespace API.Services;
|
|||
public interface IImageService
|
||||
{
|
||||
void ExtractImages(string fileFilePath, string targetDirectory, int fileCount = 1);
|
||||
string GetCoverImage(string path, string fileName, string outputDirectory, EncodeFormat encodeFormat);
|
||||
string GetCoverImage(string path, string fileName, string outputDirectory, EncodeFormat encodeFormat, CoverImageSize size);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Thumbnail version of a base64 image
|
||||
|
|
@ -40,7 +40,7 @@ public interface IImageService
|
|||
/// <param name="outputDirectory"></param>
|
||||
/// <param name="encodeFormat"></param>
|
||||
/// <returns></returns>
|
||||
string WriteCoverThumbnail(Stream stream, string fileName, string outputDirectory, EncodeFormat encodeFormat);
|
||||
string WriteCoverThumbnail(Stream stream, string fileName, string outputDirectory, EncodeFormat encodeFormat, CoverImageSize size = CoverImageSize.Default);
|
||||
/// <summary>
|
||||
/// Writes out a thumbnail by file path input
|
||||
/// </summary>
|
||||
|
|
@ -49,7 +49,7 @@ public interface IImageService
|
|||
/// <param name="outputDirectory"></param>
|
||||
/// <param name="encodeFormat"></param>
|
||||
/// <returns></returns>
|
||||
string WriteCoverThumbnail(string sourceFile, string fileName, string outputDirectory, EncodeFormat encodeFormat);
|
||||
string WriteCoverThumbnail(string sourceFile, string fileName, string outputDirectory, EncodeFormat encodeFormat, CoverImageSize size = CoverImageSize.Default);
|
||||
/// <summary>
|
||||
/// Converts the passed image to encoding and outputs it in the same directory
|
||||
/// </summary>
|
||||
|
|
@ -87,6 +87,7 @@ public class ImageService : IImageService
|
|||
/// </summary>
|
||||
public const int LibraryThumbnailWidth = 32;
|
||||
|
||||
|
||||
private static readonly string[] ValidIconRelations = {
|
||||
"icon",
|
||||
"apple-touch-icon",
|
||||
|
|
@ -124,13 +125,14 @@ public class ImageService : IImageService
|
|||
}
|
||||
}
|
||||
|
||||
public string GetCoverImage(string path, string fileName, string outputDirectory, EncodeFormat encodeFormat)
|
||||
public string GetCoverImage(string path, string fileName, string outputDirectory, EncodeFormat encodeFormat, CoverImageSize size)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path)) return string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
using var thumbnail = Image.Thumbnail(path, ThumbnailWidth, height: ThumbnailHeight, size: Enums.Size.Force);
|
||||
var dims = size.GetDimensions();
|
||||
using var thumbnail = Image.Thumbnail(path, dims.Width, height: dims.Height, size: Enums.Size.Force);
|
||||
var filename = fileName + encodeFormat.GetExtension();
|
||||
thumbnail.WriteToFile(_directoryService.FileSystem.Path.Join(outputDirectory, filename));
|
||||
return filename;
|
||||
|
|
@ -152,9 +154,10 @@ public class ImageService : IImageService
|
|||
/// <param name="outputDirectory">Where to output the file, defaults to covers directory</param>
|
||||
/// <param name="encodeFormat">Export the file as the passed encoding</param>
|
||||
/// <returns>File name with extension of the file. This will always write to <see cref="DirectoryService.CoverImageDirectory"/></returns>
|
||||
public string WriteCoverThumbnail(Stream stream, string fileName, string outputDirectory, EncodeFormat encodeFormat)
|
||||
public string WriteCoverThumbnail(Stream stream, string fileName, string outputDirectory, EncodeFormat encodeFormat, CoverImageSize size = CoverImageSize.Default)
|
||||
{
|
||||
using var thumbnail = Image.ThumbnailStream(stream, ThumbnailWidth, height: ThumbnailHeight, size: Enums.Size.Force);
|
||||
var dims = size.GetDimensions();
|
||||
using var thumbnail = Image.ThumbnailStream(stream, dims.Width, height: dims.Height, size: Enums.Size.Force);
|
||||
var filename = fileName + encodeFormat.GetExtension();
|
||||
_directoryService.ExistOrCreate(outputDirectory);
|
||||
try
|
||||
|
|
@ -165,9 +168,10 @@ public class ImageService : IImageService
|
|||
return filename;
|
||||
}
|
||||
|
||||
public string WriteCoverThumbnail(string sourceFile, string fileName, string outputDirectory, EncodeFormat encodeFormat)
|
||||
public string WriteCoverThumbnail(string sourceFile, string fileName, string outputDirectory, EncodeFormat encodeFormat, CoverImageSize size = CoverImageSize.Default)
|
||||
{
|
||||
using var thumbnail = Image.Thumbnail(sourceFile, ThumbnailWidth, height: ThumbnailHeight, size: Enums.Size.Force);
|
||||
var dims = size.GetDimensions();
|
||||
using var thumbnail = Image.Thumbnail(sourceFile, dims.Width, height: dims.Height, size: Enums.Size.Force);
|
||||
var filename = fileName + encodeFormat.GetExtension();
|
||||
_directoryService.ExistOrCreate(outputDirectory);
|
||||
try
|
||||
|
|
@ -416,31 +420,62 @@ public class ImageService : IImageService
|
|||
|
||||
public static string GetWebLinkFormat(string url, EncodeFormat encodeFormat)
|
||||
{
|
||||
return $"{new Uri(url).Host}{encodeFormat.GetExtension()}";
|
||||
return $"{new Uri(url).Host.Replace("www.", string.Empty)}{encodeFormat.GetExtension()}";
|
||||
}
|
||||
|
||||
|
||||
public static string CreateMergedImage(IList<string> coverImages, string dest)
|
||||
public static void CreateMergedImage(IList<string> coverImages, CoverImageSize size, string dest)
|
||||
{
|
||||
var image = Image.Black(ThumbnailWidth, ThumbnailHeight); // 320x455
|
||||
var dims = size.GetDimensions();
|
||||
int rows, cols;
|
||||
|
||||
var thumbnailWidth = image.Width / 2;
|
||||
var thumbnailHeight = image.Height / 2;
|
||||
if (coverImages.Count == 1)
|
||||
{
|
||||
rows = 1;
|
||||
cols = 1;
|
||||
}
|
||||
else if (coverImages.Count == 2)
|
||||
{
|
||||
rows = 1;
|
||||
cols = 2;
|
||||
}
|
||||
else if (coverImages.Count == 3)
|
||||
{
|
||||
rows = 2;
|
||||
cols = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default to 2x2 layout for more than 3 images
|
||||
rows = 2;
|
||||
cols = 2;
|
||||
}
|
||||
|
||||
var image = Image.Black(dims.Width, dims.Height);
|
||||
|
||||
var thumbnailWidth = image.Width / cols;
|
||||
var thumbnailHeight = image.Height / rows;
|
||||
|
||||
for (var i = 0; i < coverImages.Count; i++)
|
||||
{
|
||||
var tile = Image.NewFromFile(coverImages[i], access: Enums.Access.Sequential);
|
||||
|
||||
// Resize the tile to fit the thumbnail size
|
||||
tile = tile.ThumbnailImage(thumbnailWidth, height: thumbnailHeight);
|
||||
|
||||
var x = (i % 2) * thumbnailWidth;
|
||||
var y = (i / 2) * thumbnailHeight;
|
||||
var row = i / cols;
|
||||
var col = i % cols;
|
||||
|
||||
var x = col * thumbnailWidth;
|
||||
var y = row * thumbnailHeight;
|
||||
|
||||
if (coverImages.Count == 3 && i == 2)
|
||||
{
|
||||
x = (image.Width - thumbnailWidth) / 2;
|
||||
y = thumbnailHeight;
|
||||
}
|
||||
|
||||
image = image.Insert(tile, x, y);
|
||||
}
|
||||
|
||||
image.WriteToFile(dest);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue