|
@@ -107,22 +107,10 @@ public sealed class ImageProcessor : IImageProcessor, IDisposable
|
|
|
/// <inheritdoc />
|
|
|
public bool SupportsImageCollageCreation => _imageEncoder.SupportsImageCollageCreation;
|
|
|
|
|
|
- /// <inheritdoc />
|
|
|
- public async Task ProcessImage(ImageProcessingOptions options, Stream toStream)
|
|
|
- {
|
|
|
- var file = await ProcessImage(options).ConfigureAwait(false);
|
|
|
- using var fileStream = AsyncFile.OpenRead(file.Path);
|
|
|
- await fileStream.CopyToAsync(toStream).ConfigureAwait(false);
|
|
|
- }
|
|
|
-
|
|
|
/// <inheritdoc />
|
|
|
public IReadOnlyCollection<ImageFormat> GetSupportedImageOutputFormats()
|
|
|
=> _imageEncoder.SupportedOutputFormats;
|
|
|
|
|
|
- /// <inheritdoc />
|
|
|
- public bool SupportsTransparency(string path)
|
|
|
- => _transparentImageTypes.Contains(Path.GetExtension(path));
|
|
|
-
|
|
|
/// <inheritdoc />
|
|
|
public async Task<(string Path, string? MimeType, DateTime DateModified)> ProcessImage(ImageProcessingOptions options)
|
|
|
{
|
|
@@ -224,7 +212,7 @@ public sealed class ImageProcessor : IImageProcessor, IDisposable
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return (cacheFilePath, GetMimeType(outputFormat, cacheFilePath), _fileSystem.GetLastWriteTimeUtc(cacheFilePath));
|
|
|
+ return (cacheFilePath, outputFormat.GetMimeType(), _fileSystem.GetLastWriteTimeUtc(cacheFilePath));
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -262,17 +250,6 @@ public sealed class ImageProcessor : IImageProcessor, IDisposable
|
|
|
return ImageFormat.Jpg;
|
|
|
}
|
|
|
|
|
|
- private string GetMimeType(ImageFormat format, string path)
|
|
|
- => format switch
|
|
|
- {
|
|
|
- ImageFormat.Bmp => MimeTypes.GetMimeType("i.bmp"),
|
|
|
- ImageFormat.Gif => MimeTypes.GetMimeType("i.gif"),
|
|
|
- ImageFormat.Jpg => MimeTypes.GetMimeType("i.jpg"),
|
|
|
- ImageFormat.Png => MimeTypes.GetMimeType("i.png"),
|
|
|
- ImageFormat.Webp => MimeTypes.GetMimeType("i.webp"),
|
|
|
- _ => MimeTypes.GetMimeType(path)
|
|
|
- };
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// Gets the cache file path based on a set of parameters.
|
|
|
/// </summary>
|
|
@@ -374,7 +351,7 @@ public sealed class ImageProcessor : IImageProcessor, IDisposable
|
|
|
filename.Append(",v=");
|
|
|
filename.Append(Version);
|
|
|
|
|
|
- return GetCachePath(ResizedImageCachePath, filename.ToString(), "." + format.ToString().ToLowerInvariant());
|
|
|
+ return GetCachePath(ResizedImageCachePath, filename.ToString(), format.GetExtension());
|
|
|
}
|
|
|
|
|
|
/// <inheritdoc />
|
|
@@ -471,35 +448,6 @@ public sealed class ImageProcessor : IImageProcessor, IDisposable
|
|
|
return Task.FromResult((originalImagePath, dateModified));
|
|
|
}
|
|
|
|
|
|
- // TODO _mediaEncoder.ConvertImage is not implemented
|
|
|
- // if (!_imageEncoder.SupportedInputFormats.Contains(inputFormat))
|
|
|
- // {
|
|
|
- // try
|
|
|
- // {
|
|
|
- // string filename = (originalImagePath + dateModified.Ticks.ToString(CultureInfo.InvariantCulture)).GetMD5().ToString("N", CultureInfo.InvariantCulture);
|
|
|
- //
|
|
|
- // string cacheExtension = _mediaEncoder.SupportsEncoder("libwebp") ? ".webp" : ".png";
|
|
|
- // var outputPath = Path.Combine(_appPaths.ImageCachePath, "converted-images", filename + cacheExtension);
|
|
|
- //
|
|
|
- // var file = _fileSystem.GetFileInfo(outputPath);
|
|
|
- // if (!file.Exists)
|
|
|
- // {
|
|
|
- // await _mediaEncoder.ConvertImage(originalImagePath, outputPath).ConfigureAwait(false);
|
|
|
- // dateModified = _fileSystem.GetLastWriteTimeUtc(outputPath);
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // dateModified = file.LastWriteTimeUtc;
|
|
|
- // }
|
|
|
- //
|
|
|
- // originalImagePath = outputPath;
|
|
|
- // }
|
|
|
- // catch (Exception ex)
|
|
|
- // {
|
|
|
- // _logger.LogError(ex, "Image conversion failed for {Path}", originalImagePath);
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
return Task.FromResult((originalImagePath, dateModified));
|
|
|
}
|
|
|
|