| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Globalization; |
| | 4 | | using System.IO; |
| | 5 | | using System.Linq; |
| | 6 | | using System.Net.Mime; |
| | 7 | | using System.Text; |
| | 8 | | using System.Threading; |
| | 9 | | using System.Threading.Tasks; |
| | 10 | | using AsyncKeyedLock; |
| | 11 | | using Jellyfin.Data.Entities; |
| | 12 | | using MediaBrowser.Common.Extensions; |
| | 13 | | using MediaBrowser.Controller; |
| | 14 | | using MediaBrowser.Controller.Configuration; |
| | 15 | | using MediaBrowser.Controller.Drawing; |
| | 16 | | using MediaBrowser.Controller.Entities; |
| | 17 | | using MediaBrowser.Model.Drawing; |
| | 18 | | using MediaBrowser.Model.Entities; |
| | 19 | | using MediaBrowser.Model.IO; |
| | 20 | | using MediaBrowser.Model.Net; |
| | 21 | | using Microsoft.Extensions.Logging; |
| | 22 | | using Photo = MediaBrowser.Controller.Entities.Photo; |
| | 23 | |
|
| | 24 | | namespace Jellyfin.Drawing; |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Class ImageProcessor. |
| | 28 | | /// </summary> |
| | 29 | | public sealed class ImageProcessor : IImageProcessor, IDisposable |
| | 30 | | { |
| | 31 | | // Increment this when there's a change requiring caches to be invalidated |
| | 32 | | private const char Version = '3'; |
| | 33 | |
|
| 0 | 34 | | private static readonly HashSet<string> _transparentImageTypes |
| 0 | 35 | | = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".png", ".webp", ".gif" }; |
| | 36 | |
|
| | 37 | | private readonly ILogger<ImageProcessor> _logger; |
| | 38 | | private readonly IFileSystem _fileSystem; |
| | 39 | | private readonly IServerApplicationPaths _appPaths; |
| | 40 | | private readonly IImageEncoder _imageEncoder; |
| | 41 | |
|
| | 42 | | private readonly AsyncNonKeyedLocker _parallelEncodingLimit; |
| | 43 | |
|
| | 44 | | private bool _disposed; |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// Initializes a new instance of the <see cref="ImageProcessor"/> class. |
| | 48 | | /// </summary> |
| | 49 | | /// <param name="logger">The logger.</param> |
| | 50 | | /// <param name="appPaths">The server application paths.</param> |
| | 51 | | /// <param name="fileSystem">The filesystem.</param> |
| | 52 | | /// <param name="imageEncoder">The image encoder.</param> |
| | 53 | | /// <param name="config">The configuration.</param> |
| | 54 | | public ImageProcessor( |
| | 55 | | ILogger<ImageProcessor> logger, |
| | 56 | | IServerApplicationPaths appPaths, |
| | 57 | | IFileSystem fileSystem, |
| | 58 | | IImageEncoder imageEncoder, |
| | 59 | | IServerConfigurationManager config) |
| | 60 | | { |
| 22 | 61 | | _logger = logger; |
| 22 | 62 | | _fileSystem = fileSystem; |
| 22 | 63 | | _imageEncoder = imageEncoder; |
| 22 | 64 | | _appPaths = appPaths; |
| | 65 | |
|
| 22 | 66 | | var semaphoreCount = config.Configuration.ParallelImageEncodingLimit; |
| 22 | 67 | | if (semaphoreCount < 1) |
| | 68 | | { |
| 22 | 69 | | semaphoreCount = 2 * Environment.ProcessorCount; |
| | 70 | | } |
| | 71 | |
|
| 22 | 72 | | _parallelEncodingLimit = new(semaphoreCount); |
| 22 | 73 | | } |
| | 74 | |
|
| 0 | 75 | | private string ResizedImageCachePath => Path.Combine(_appPaths.ImageCachePath, "resized-images"); |
| | 76 | |
|
| | 77 | | /// <inheritdoc /> |
| | 78 | | public IReadOnlyCollection<string> SupportedInputFormats => |
| 0 | 79 | | new HashSet<string>(StringComparer.OrdinalIgnoreCase) |
| 0 | 80 | | { |
| 0 | 81 | | "tiff", |
| 0 | 82 | | "tif", |
| 0 | 83 | | "jpeg", |
| 0 | 84 | | "jpg", |
| 0 | 85 | | "png", |
| 0 | 86 | | "aiff", |
| 0 | 87 | | "cr2", |
| 0 | 88 | | "crw", |
| 0 | 89 | | "nef", |
| 0 | 90 | | "orf", |
| 0 | 91 | | "pef", |
| 0 | 92 | | "arw", |
| 0 | 93 | | "webp", |
| 0 | 94 | | "gif", |
| 0 | 95 | | "bmp", |
| 0 | 96 | | "erf", |
| 0 | 97 | | "raf", |
| 0 | 98 | | "rw2", |
| 0 | 99 | | "nrw", |
| 0 | 100 | | "dng", |
| 0 | 101 | | "ico", |
| 0 | 102 | | "astc", |
| 0 | 103 | | "ktx", |
| 0 | 104 | | "pkm", |
| 0 | 105 | | "wbmp", |
| 0 | 106 | | "avif" |
| 0 | 107 | | }; |
| | 108 | |
|
| | 109 | | /// <inheritdoc /> |
| 0 | 110 | | public bool SupportsImageCollageCreation => _imageEncoder.SupportsImageCollageCreation; |
| | 111 | |
|
| | 112 | | /// <inheritdoc /> |
| | 113 | | public IReadOnlyCollection<ImageFormat> GetSupportedImageOutputFormats() |
| 0 | 114 | | => _imageEncoder.SupportedOutputFormats; |
| | 115 | |
|
| | 116 | | /// <inheritdoc /> |
| | 117 | | public async Task<(string Path, string? MimeType, DateTime DateModified)> ProcessImage(ImageProcessingOptions option |
| | 118 | | { |
| | 119 | | ItemImageInfo originalImage = options.Image; |
| | 120 | | BaseItem item = options.Item; |
| | 121 | |
|
| | 122 | | string originalImagePath = originalImage.Path; |
| | 123 | | DateTime dateModified = originalImage.DateModified; |
| | 124 | | ImageDimensions? originalImageSize = null; |
| | 125 | | if (originalImage.Width > 0 && originalImage.Height > 0) |
| | 126 | | { |
| | 127 | | originalImageSize = new ImageDimensions(originalImage.Width, originalImage.Height); |
| | 128 | | } |
| | 129 | |
|
| | 130 | | var mimeType = MimeTypes.GetMimeType(originalImagePath); |
| | 131 | | if (!_imageEncoder.SupportsImageEncoding) |
| | 132 | | { |
| | 133 | | return (originalImagePath, mimeType, dateModified); |
| | 134 | | } |
| | 135 | |
|
| | 136 | | var supportedImageInfo = await GetSupportedImage(originalImagePath, dateModified).ConfigureAwait(false); |
| | 137 | | originalImagePath = supportedImageInfo.Path; |
| | 138 | |
|
| | 139 | | // Original file doesn't exist, or original file is gif. |
| | 140 | | if (!File.Exists(originalImagePath) || string.Equals(mimeType, MediaTypeNames.Image.Gif, StringComparison.Ordina |
| | 141 | | { |
| | 142 | | return (originalImagePath, mimeType, dateModified); |
| | 143 | | } |
| | 144 | |
|
| | 145 | | dateModified = supportedImageInfo.DateModified; |
| | 146 | | bool requiresTransparency = _transparentImageTypes.Contains(Path.GetExtension(originalImagePath)); |
| | 147 | |
|
| | 148 | | bool autoOrient = false; |
| | 149 | | ImageOrientation? orientation = null; |
| | 150 | | if (item is Photo photo) |
| | 151 | | { |
| | 152 | | if (photo.Orientation.HasValue) |
| | 153 | | { |
| | 154 | | if (photo.Orientation.Value != ImageOrientation.TopLeft) |
| | 155 | | { |
| | 156 | | autoOrient = true; |
| | 157 | | orientation = photo.Orientation; |
| | 158 | | } |
| | 159 | | } |
| | 160 | | else |
| | 161 | | { |
| | 162 | | // Orientation unknown, so do it |
| | 163 | | autoOrient = true; |
| | 164 | | orientation = photo.Orientation; |
| | 165 | | } |
| | 166 | | } |
| | 167 | |
|
| | 168 | | if (options.HasDefaultOptions(originalImagePath, originalImageSize) && (!autoOrient || !options.RequiresAutoOrie |
| | 169 | | { |
| | 170 | | // Just spit out the original file if all the options are default |
| | 171 | | return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); |
| | 172 | | } |
| | 173 | |
|
| | 174 | | int quality = options.Quality; |
| | 175 | |
|
| | 176 | | ImageFormat outputFormat = GetOutputFormat(options.SupportedOutputFormats, requiresTransparency); |
| | 177 | | string cacheFilePath = GetCacheFilePath( |
| | 178 | | originalImagePath, |
| | 179 | | options.Width, |
| | 180 | | options.Height, |
| | 181 | | options.MaxWidth, |
| | 182 | | options.MaxHeight, |
| | 183 | | options.FillWidth, |
| | 184 | | options.FillHeight, |
| | 185 | | quality, |
| | 186 | | dateModified, |
| | 187 | | outputFormat, |
| | 188 | | options.PercentPlayed, |
| | 189 | | options.UnplayedCount, |
| | 190 | | options.Blur, |
| | 191 | | options.BackgroundColor, |
| | 192 | | options.ForegroundLayer); |
| | 193 | |
|
| | 194 | | try |
| | 195 | | { |
| | 196 | | if (!File.Exists(cacheFilePath)) |
| | 197 | | { |
| | 198 | | string resultPath; |
| | 199 | |
|
| | 200 | | // Limit number of parallel (more precisely: concurrent) image encodings to prevent a high memory usage |
| | 201 | | using (await _parallelEncodingLimit.LockAsync().ConfigureAwait(false)) |
| | 202 | | { |
| | 203 | | resultPath = _imageEncoder.EncodeImage(originalImagePath, dateModified, cacheFilePath, autoOrient, o |
| | 204 | | } |
| | 205 | |
|
| | 206 | | if (string.Equals(resultPath, originalImagePath, StringComparison.OrdinalIgnoreCase)) |
| | 207 | | { |
| | 208 | | return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); |
| | 209 | | } |
| | 210 | | } |
| | 211 | |
|
| | 212 | | return (cacheFilePath, outputFormat.GetMimeType(), _fileSystem.GetLastWriteTimeUtc(cacheFilePath)); |
| | 213 | | } |
| | 214 | | catch (Exception ex) |
| | 215 | | { |
| | 216 | | // If it fails for whatever reason, return the original image |
| | 217 | | _logger.LogError(ex, "Error encoding image"); |
| | 218 | | return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); |
| | 219 | | } |
| | 220 | | } |
| | 221 | |
|
| | 222 | | private ImageFormat GetOutputFormat(IReadOnlyCollection<ImageFormat> clientSupportedFormats, bool requiresTransparen |
| | 223 | | { |
| 0 | 224 | | var serverFormats = GetSupportedImageOutputFormats(); |
| | 225 | |
|
| | 226 | | // Client doesn't care about format, so start with webp if supported |
| 0 | 227 | | if (serverFormats.Contains(ImageFormat.Webp) && clientSupportedFormats.Contains(ImageFormat.Webp)) |
| | 228 | | { |
| 0 | 229 | | return ImageFormat.Webp; |
| | 230 | | } |
| | 231 | |
|
| | 232 | | // If transparency is needed and webp isn't supported, than png is the only option |
| 0 | 233 | | if (requiresTransparency && clientSupportedFormats.Contains(ImageFormat.Png)) |
| | 234 | | { |
| 0 | 235 | | return ImageFormat.Png; |
| | 236 | | } |
| | 237 | |
|
| 0 | 238 | | foreach (var format in clientSupportedFormats) |
| | 239 | | { |
| 0 | 240 | | if (serverFormats.Contains(format)) |
| | 241 | | { |
| 0 | 242 | | return format; |
| | 243 | | } |
| | 244 | | } |
| | 245 | |
|
| | 246 | | // We should never actually get here |
| 0 | 247 | | return ImageFormat.Jpg; |
| 0 | 248 | | } |
| | 249 | |
|
| | 250 | | /// <summary> |
| | 251 | | /// Gets the cache file path based on a set of parameters. |
| | 252 | | /// </summary> |
| | 253 | | private string GetCacheFilePath( |
| | 254 | | string originalPath, |
| | 255 | | int? width, |
| | 256 | | int? height, |
| | 257 | | int? maxWidth, |
| | 258 | | int? maxHeight, |
| | 259 | | int? fillWidth, |
| | 260 | | int? fillHeight, |
| | 261 | | int quality, |
| | 262 | | DateTime dateModified, |
| | 263 | | ImageFormat format, |
| | 264 | | double percentPlayed, |
| | 265 | | int? unwatchedCount, |
| | 266 | | int? blur, |
| | 267 | | string backgroundColor, |
| | 268 | | string foregroundLayer) |
| | 269 | | { |
| 0 | 270 | | var filename = new StringBuilder(256); |
| 0 | 271 | | filename.Append(originalPath); |
| | 272 | |
|
| 0 | 273 | | filename.Append(",quality="); |
| 0 | 274 | | filename.Append(quality); |
| | 275 | |
|
| 0 | 276 | | filename.Append(",datemodified="); |
| 0 | 277 | | filename.Append(dateModified.Ticks); |
| | 278 | |
|
| 0 | 279 | | filename.Append(",f="); |
| 0 | 280 | | filename.Append(format); |
| | 281 | |
|
| 0 | 282 | | if (width.HasValue) |
| | 283 | | { |
| 0 | 284 | | filename.Append(",width="); |
| 0 | 285 | | filename.Append(width.Value); |
| | 286 | | } |
| | 287 | |
|
| 0 | 288 | | if (height.HasValue) |
| | 289 | | { |
| 0 | 290 | | filename.Append(",height="); |
| 0 | 291 | | filename.Append(height.Value); |
| | 292 | | } |
| | 293 | |
|
| 0 | 294 | | if (maxWidth.HasValue) |
| | 295 | | { |
| 0 | 296 | | filename.Append(",maxwidth="); |
| 0 | 297 | | filename.Append(maxWidth.Value); |
| | 298 | | } |
| | 299 | |
|
| 0 | 300 | | if (maxHeight.HasValue) |
| | 301 | | { |
| 0 | 302 | | filename.Append(",maxheight="); |
| 0 | 303 | | filename.Append(maxHeight.Value); |
| | 304 | | } |
| | 305 | |
|
| 0 | 306 | | if (fillWidth.HasValue) |
| | 307 | | { |
| 0 | 308 | | filename.Append(",fillwidth="); |
| 0 | 309 | | filename.Append(fillWidth.Value); |
| | 310 | | } |
| | 311 | |
|
| 0 | 312 | | if (fillHeight.HasValue) |
| | 313 | | { |
| 0 | 314 | | filename.Append(",fillheight="); |
| 0 | 315 | | filename.Append(fillHeight.Value); |
| | 316 | | } |
| | 317 | |
|
| 0 | 318 | | if (percentPlayed > 0) |
| | 319 | | { |
| 0 | 320 | | filename.Append(",p="); |
| 0 | 321 | | filename.Append(percentPlayed); |
| | 322 | | } |
| | 323 | |
|
| 0 | 324 | | if (unwatchedCount.HasValue) |
| | 325 | | { |
| 0 | 326 | | filename.Append(",p="); |
| 0 | 327 | | filename.Append(unwatchedCount.Value); |
| | 328 | | } |
| | 329 | |
|
| 0 | 330 | | if (blur.HasValue) |
| | 331 | | { |
| 0 | 332 | | filename.Append(",blur="); |
| 0 | 333 | | filename.Append(blur.Value); |
| | 334 | | } |
| | 335 | |
|
| 0 | 336 | | if (!string.IsNullOrEmpty(backgroundColor)) |
| | 337 | | { |
| 0 | 338 | | filename.Append(",b="); |
| 0 | 339 | | filename.Append(backgroundColor); |
| | 340 | | } |
| | 341 | |
|
| 0 | 342 | | if (!string.IsNullOrEmpty(foregroundLayer)) |
| | 343 | | { |
| 0 | 344 | | filename.Append(",fl="); |
| 0 | 345 | | filename.Append(foregroundLayer); |
| | 346 | | } |
| | 347 | |
|
| 0 | 348 | | filename.Append(",v="); |
| 0 | 349 | | filename.Append(Version); |
| | 350 | |
|
| 0 | 351 | | return GetCachePath(ResizedImageCachePath, filename.ToString(), format.GetExtension()); |
| | 352 | | } |
| | 353 | |
|
| | 354 | | /// <inheritdoc /> |
| | 355 | | public ImageDimensions GetImageDimensions(BaseItem item, ItemImageInfo info) |
| | 356 | | { |
| 0 | 357 | | int width = info.Width; |
| 0 | 358 | | int height = info.Height; |
| | 359 | |
|
| 0 | 360 | | if (height > 0 && width > 0) |
| | 361 | | { |
| 0 | 362 | | return new ImageDimensions(width, height); |
| | 363 | | } |
| | 364 | |
|
| 0 | 365 | | string path = info.Path; |
| 0 | 366 | | _logger.LogDebug("Getting image size for item {ItemType} {Path}", item.GetType().Name, path); |
| | 367 | |
|
| 0 | 368 | | ImageDimensions size = GetImageDimensions(path); |
| 0 | 369 | | info.Width = size.Width; |
| 0 | 370 | | info.Height = size.Height; |
| | 371 | |
|
| 0 | 372 | | return size; |
| | 373 | | } |
| | 374 | |
|
| | 375 | | /// <inheritdoc /> |
| | 376 | | public ImageDimensions GetImageDimensions(string path) |
| 0 | 377 | | => _imageEncoder.GetImageSize(path); |
| | 378 | |
|
| | 379 | | /// <inheritdoc /> |
| | 380 | | public string GetImageBlurHash(string path) |
| | 381 | | { |
| 0 | 382 | | var size = GetImageDimensions(path); |
| 0 | 383 | | return GetImageBlurHash(path, size); |
| | 384 | | } |
| | 385 | |
|
| | 386 | | /// <inheritdoc /> |
| | 387 | | public string GetImageBlurHash(string path, ImageDimensions imageDimensions) |
| | 388 | | { |
| 0 | 389 | | if (imageDimensions.Width <= 0 || imageDimensions.Height <= 0) |
| | 390 | | { |
| 0 | 391 | | return string.Empty; |
| | 392 | | } |
| | 393 | |
|
| | 394 | | // We want tiles to be as close to square as possible, and to *mostly* keep under 16 tiles for performance. |
| | 395 | | // One tile is (width / xComp) x (height / yComp) pixels, which means that ideally yComp = xComp * height / widt |
| | 396 | | // See more at https://github.com/woltapp/blurhash/#how-do-i-pick-the-number-of-x-and-y-components |
| 0 | 397 | | float xCompF = MathF.Sqrt(16.0f * imageDimensions.Width / imageDimensions.Height); |
| 0 | 398 | | float yCompF = xCompF * imageDimensions.Height / imageDimensions.Width; |
| | 399 | |
|
| 0 | 400 | | int xComp = Math.Min((int)xCompF + 1, 9); |
| 0 | 401 | | int yComp = Math.Min((int)yCompF + 1, 9); |
| | 402 | |
|
| 0 | 403 | | return _imageEncoder.GetImageBlurHash(xComp, yComp, path); |
| | 404 | | } |
| | 405 | |
|
| | 406 | | /// <inheritdoc /> |
| | 407 | | public string GetImageCacheTag(BaseItem item, ItemImageInfo image) |
| 0 | 408 | | => (item.Path + image.DateModified.Ticks).GetMD5().ToString("N", CultureInfo.InvariantCulture); |
| | 409 | |
|
| | 410 | | /// <inheritdoc /> |
| | 411 | | public string? GetImageCacheTag(BaseItem item, ChapterInfo chapter) |
| | 412 | | { |
| 0 | 413 | | if (chapter.ImagePath is null) |
| | 414 | | { |
| 0 | 415 | | return null; |
| | 416 | | } |
| | 417 | |
|
| 0 | 418 | | return GetImageCacheTag(item, new ItemImageInfo |
| 0 | 419 | | { |
| 0 | 420 | | Path = chapter.ImagePath, |
| 0 | 421 | | Type = ImageType.Chapter, |
| 0 | 422 | | DateModified = chapter.ImageDateModified |
| 0 | 423 | | }); |
| | 424 | | } |
| | 425 | |
|
| | 426 | | /// <inheritdoc /> |
| | 427 | | public string? GetImageCacheTag(User user) |
| | 428 | | { |
| 0 | 429 | | if (user.ProfileImage is null) |
| | 430 | | { |
| 0 | 431 | | return null; |
| | 432 | | } |
| | 433 | |
|
| 0 | 434 | | return (user.ProfileImage.Path + user.ProfileImage.LastModified.Ticks).GetMD5() |
| 0 | 435 | | .ToString("N", CultureInfo.InvariantCulture); |
| | 436 | | } |
| | 437 | |
|
| | 438 | | private Task<(string Path, DateTime DateModified)> GetSupportedImage(string originalImagePath, DateTime dateModified |
| | 439 | | { |
| 0 | 440 | | var inputFormat = Path.GetExtension(originalImagePath.AsSpan()).TrimStart('.').ToString(); |
| | 441 | |
|
| | 442 | | // These are just jpg files renamed as tbn |
| 0 | 443 | | if (string.Equals(inputFormat, "tbn", StringComparison.OrdinalIgnoreCase)) |
| | 444 | | { |
| 0 | 445 | | return Task.FromResult((originalImagePath, dateModified)); |
| | 446 | | } |
| | 447 | |
|
| | 448 | | return Task.FromResult((originalImagePath, dateModified)); |
| | 449 | | } |
| | 450 | |
|
| | 451 | | /// <summary> |
| | 452 | | /// Gets the cache path. |
| | 453 | | /// </summary> |
| | 454 | | /// <param name="path">The path.</param> |
| | 455 | | /// <param name="uniqueName">Name of the unique.</param> |
| | 456 | | /// <param name="fileExtension">The file extension.</param> |
| | 457 | | /// <returns>System.String.</returns> |
| | 458 | | /// <exception cref="ArgumentNullException"> |
| | 459 | | /// path |
| | 460 | | /// or |
| | 461 | | /// uniqueName |
| | 462 | | /// or |
| | 463 | | /// fileExtension. |
| | 464 | | /// </exception> |
| | 465 | | public string GetCachePath(string path, string uniqueName, string fileExtension) |
| | 466 | | { |
| 0 | 467 | | ArgumentException.ThrowIfNullOrEmpty(path); |
| 0 | 468 | | ArgumentException.ThrowIfNullOrEmpty(uniqueName); |
| 0 | 469 | | ArgumentException.ThrowIfNullOrEmpty(fileExtension); |
| | 470 | |
|
| 0 | 471 | | var filename = uniqueName.GetMD5() + fileExtension; |
| | 472 | |
|
| 0 | 473 | | return GetCachePath(path, filename); |
| | 474 | | } |
| | 475 | |
|
| | 476 | | /// <summary> |
| | 477 | | /// Gets the cache path. |
| | 478 | | /// </summary> |
| | 479 | | /// <param name="path">The path.</param> |
| | 480 | | /// <param name="filename">The filename.</param> |
| | 481 | | /// <returns>System.String.</returns> |
| | 482 | | /// <exception cref="ArgumentNullException"> |
| | 483 | | /// path |
| | 484 | | /// or |
| | 485 | | /// filename. |
| | 486 | | /// </exception> |
| | 487 | | public string GetCachePath(ReadOnlySpan<char> path, ReadOnlySpan<char> filename) |
| | 488 | | { |
| 0 | 489 | | if (path.IsEmpty) |
| | 490 | | { |
| 0 | 491 | | throw new ArgumentException("Path can't be empty.", nameof(path)); |
| | 492 | | } |
| | 493 | |
|
| 0 | 494 | | if (filename.IsEmpty) |
| | 495 | | { |
| 0 | 496 | | throw new ArgumentException("Filename can't be empty.", nameof(filename)); |
| | 497 | | } |
| | 498 | |
|
| 0 | 499 | | var prefix = filename.Slice(0, 1); |
| | 500 | |
|
| 0 | 501 | | return Path.Join(path, prefix, filename); |
| | 502 | | } |
| | 503 | |
|
| | 504 | | /// <inheritdoc /> |
| | 505 | | public void CreateImageCollage(ImageCollageOptions options, string? libraryName) |
| | 506 | | { |
| 0 | 507 | | _logger.LogInformation("Creating image collage and saving to {Path}", options.OutputPath); |
| | 508 | |
|
| 0 | 509 | | _imageEncoder.CreateImageCollage(options, libraryName); |
| | 510 | |
|
| 0 | 511 | | _logger.LogInformation("Completed creation of image collage and saved to {Path}", options.OutputPath); |
| 0 | 512 | | } |
| | 513 | |
|
| | 514 | | /// <inheritdoc /> |
| | 515 | | public void Dispose() |
| | 516 | | { |
| 22 | 517 | | if (_disposed) |
| | 518 | | { |
| 0 | 519 | | return; |
| | 520 | | } |
| | 521 | |
|
| 22 | 522 | | if (_imageEncoder is IDisposable disposable) |
| | 523 | | { |
| 0 | 524 | | disposable.Dispose(); |
| | 525 | | } |
| | 526 | |
|
| 22 | 527 | | _parallelEncodingLimit?.Dispose(); |
| | 528 | |
|
| 22 | 529 | | _disposed = true; |
| 22 | 530 | | } |
| | 531 | | } |