| | | 1 | | using Anichron.Core.Domain; |
| | | 2 | | using SixLabors.ImageSharp; |
| | | 3 | | using SixLabors.ImageSharp.PixelFormats; |
| | | 4 | | using System.Text; |
| | | 5 | | |
| | | 6 | | namespace Anichron.Worker.Ingestion.Proxy; |
| | | 7 | | |
| | | 8 | | internal interface IImageProxyGenerator |
| | | 9 | | { |
| | | 10 | | string FileName { get; } |
| | | 11 | | ProxyType ProxyType { get; } |
| | | 12 | | Task<byte[]> GenerateAsync(Image<Rgba32> image, CancellationToken ct); |
| | | 13 | | } |
| | | 14 | | |
| | | 15 | | internal sealed class ThumbnailGenerator(IImageProcessor imageProcessor) : IImageProxyGenerator |
| | | 16 | | { |
| | | 17 | | public string FileName => "thumbnail.jpg"; |
| | | 18 | | public ProxyType ProxyType => ProxyType.Thumbnail; |
| | | 19 | | public Task<byte[]> GenerateAsync(Image<Rgba32> image, CancellationToken ct) |
| | | 20 | | => imageProcessor.CreateThumbnailAsync(image, ct); |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | internal sealed class FullPreviewGenerator(IImageProcessor imageProcessor) : IImageProxyGenerator |
| | | 24 | | { |
| | | 25 | | public string FileName => "preview.jpg"; |
| | | 26 | | public ProxyType ProxyType => ProxyType.FullPreview; |
| | | 27 | | public Task<byte[]> GenerateAsync(Image<Rgba32> image, CancellationToken ct) |
| | | 28 | | => imageProcessor.CreateFullPreviewAsync(image, ct); |
| | | 29 | | } |
| | | 30 | | |
| | 21 | 31 | | internal sealed class BlurhashGenerator(IImageProcessor imageProcessor) : IImageProxyGenerator |
| | | 32 | | { |
| | 17 | 33 | | public string FileName => "blurhash.txt"; |
| | 17 | 34 | | public ProxyType ProxyType => ProxyType.BlurHash; |
| | | 35 | | public async Task<byte[]> GenerateAsync(Image<Rgba32> image, CancellationToken ct) |
| | 18 | 36 | | { |
| | 18 | 37 | | var hash = await imageProcessor.ComputeBlurhashAsync(image, ct); |
| | 18 | 38 | | return Encoding.UTF8.GetBytes(hash); |
| | 18 | 39 | | } |
| | | 40 | | } |