Class StandardThumbnailerClient
- Namespace
- PommaLabs.Thumbnailer.Client
- Assembly
- PommaLabs.Thumbnailer.Client.dll
Standard Thumbnailer client.
public sealed class StandardThumbnailerClient : IThumbnailerClient, IDisposable
- Inheritance
-
StandardThumbnailerClient
- Implements
- Inherited Members
Constructors
StandardThumbnailerClient(IOptions<ThumbnailerClientConfiguration>, ILogger<StandardThumbnailerClient>)
Constructor.
public StandardThumbnailerClient(IOptions<ThumbnailerClientConfiguration> clientConfiguration, ILogger<StandardThumbnailerClient> logger)
Parameters
clientConfigurationIOptions<ThumbnailerClientConfiguration>Thumbnailer client configuration.
loggerILogger<StandardThumbnailerClient>Logger.
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GenerateImagePlaceholderAsync(byte[], ImagePlaceholderAlgorithm, string?, string?, CancellationToken)
Generates a placeholder of given image.
public Task<ImagePlaceholderResult> GenerateImagePlaceholderAsync(byte[] contents, ImagePlaceholderAlgorithm imagePlaceholderAlgorithm, string? contentType = null, string? fileName = null, CancellationToken cancellationToken = default)
Parameters
contentsbyte[]File bytes.
imagePlaceholderAlgorithmImagePlaceholderAlgorithmDesired placeholder generation algorithm.
contentTypestringFile content type. If not specified, it will be deduced from file signature: however, please specify it if available.
fileNamestringFile name. If not specified, its value will be a random file name compatible with specified (or deduced) content type.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<ImagePlaceholderResult>
A very compact representation of given source image.
GenerateImagePlaceholderAsync(Uri, ImagePlaceholderAlgorithm, CancellationToken)
Generates a placeholder of given image.
public Task<ImagePlaceholderResult> GenerateImagePlaceholderAsync(Uri fileUri, ImagePlaceholderAlgorithm imagePlaceholderAlgorithm, CancellationToken cancellationToken = default)
Parameters
fileUriUriSource file URI.
imagePlaceholderAlgorithmImagePlaceholderAlgorithmDesired placeholder generation algorithm.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<ImagePlaceholderResult>
A very compact representation of given source image.
GenerateThumbnailAsync(byte[], string?, string?, ushort, ushort, ushort, bool, bool, bool, ImagePlaceholderAlgorithm, ThumbnailFormat, ushort, CancellationToken)
Produces a thumbnail of given source file.
public Task<FileResult> GenerateThumbnailAsync(byte[] contents, string? contentType = null, string? fileName = null, ushort widthPx = 256, ushort heightPx = 256, ushort shavePx = 0, bool fill = true, bool smartCrop = false, bool fallback = false, ImagePlaceholderAlgorithm imagePlaceholderAlgorithm = ImagePlaceholderAlgorithm.None, ThumbnailFormat format = ThumbnailFormat.Png, ushort dpi = 72, CancellationToken cancellationToken = default)
Parameters
contentsbyte[]File bytes.
contentTypestringFile content type. If not specified, it will be deduced from file signature: however, please specify it if available.
fileNamestringFile name. If not specified, its value will be a random file name compatible with specified (or deduced) content type.
widthPxushortMax thumbnail width. Thumbnail will be generated preserving the source file aspect ratio and, if
fillis true, a transparent background will be added so that thumbnail width and height are exactly as requested.heightPxushortMax thumbnail height. Thumbnail will be generated preserving the source file aspect ratio and, if
fillis true, a transparent background will be added so that thumbnail width and height are exactly as requested.shavePxushortShaves
shavePxfrom source file edges.fillboolIf true, a transparent background will be added so that thumbnail width and height are exactly as requested, preserving source file aspect ratio. When
smartCropis enabled, this parameter will be ignored. Defaults to true.smartCropboolFinds a good crop which satisfies specified
widthPxandheightPxparameters. When smart crop is enabled,fillis ignored. Defaults to false.fallbackboolIf true, a fallback image is generated when thumbnail generation fails. Fallback image is generated starting from an SVG template, whose customization is documented in project README. Defaults to false.
imagePlaceholderAlgorithmImagePlaceholderAlgorithmDesired placeholder generation algorithm. Defaults to None.
formatThumbnailFormatWhich format to use for generated thumbnails. Defaults to Png.
dpiushortDots per inch (DPI) to set on output images. Defaults to 72.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<FileResult>
A thumbnail of given source file.
GenerateThumbnailAsync(Uri, ushort, ushort, ushort, bool, bool, bool, ImagePlaceholderAlgorithm, ThumbnailFormat, ushort, CancellationToken)
Produces a thumbnail of given source file.
public Task<FileResult> GenerateThumbnailAsync(Uri fileUri, ushort widthPx = 256, ushort heightPx = 256, ushort shavePx = 0, bool fill = true, bool smartCrop = false, bool fallback = false, ImagePlaceholderAlgorithm imagePlaceholderAlgorithm = ImagePlaceholderAlgorithm.None, ThumbnailFormat format = ThumbnailFormat.Png, ushort dpi = 72, CancellationToken cancellationToken = default)
Parameters
fileUriUriSource file URI.
widthPxushortMax thumbnail width. Thumbnail will be generated preserving the source file aspect ratio and, if
fillis true, a transparent background will be added so that thumbnail width and height are exactly as requested.heightPxushortMax thumbnail height. Thumbnail will be generated preserving the source file aspect ratio and, if
fillis true, a transparent background will be added so that thumbnail width and height are exactly as requested.shavePxushortShaves
shavePxfrom source file edges.fillboolIf true, a transparent background will be added so that thumbnail width and height are exactly as requested, preserving source file aspect ratio. When
smartCropis enabled, this parameter will be ignored. Defaults to true.smartCropboolFinds a good crop which satisfies specified
widthPxandheightPxparameters. When smart crop is enabled,fillis ignored. Defaults to false.fallbackboolIf true, a fallback image is generated when thumbnail generation fails. Fallback image is generated starting from an SVG template, whose customization is documented in project README. Defaults to false.
imagePlaceholderAlgorithmImagePlaceholderAlgorithmDesired placeholder generation algorithm. Defaults to None.
formatThumbnailFormatWhich format to use for generated thumbnails. Defaults to Png.
dpiushortDots per inch (DPI) to set on output images. Defaults to 72.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<FileResult>
A thumbnail of given source file.
IsHealthyAsync(CancellationToken)
Checks whether Thumbnailer service is healthy or not.
public Task<bool> IsHealthyAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancellation token.
Returns
IsImagePlaceholderGenerationSupportedAsync(string, CancellationToken)
Returns true if given content type is supported by image placeholder generation, false otherwise.
public Task<bool> IsImagePlaceholderGenerationSupportedAsync(string contentType, CancellationToken cancellationToken = default)
Parameters
contentTypestringContent type.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<bool>
True if given content type is supported by image placeholder generation, false otherwise.
IsMediaOptimizationSupportedAsync(string, CancellationToken)
Returns true if given content type is supported by media file optimization with specified mode, false otherwise.
public Task<bool> IsMediaOptimizationSupportedAsync(string contentType, CancellationToken cancellationToken = default)
Parameters
contentTypestringContent type.
cancellationTokenCancellationTokenCancellation token.
Returns
IsThumbnailGenerationSupportedAsync(string, CancellationToken)
Returns true if given content type is supported by thumbnail generation, false otherwise.
public Task<bool> IsThumbnailGenerationSupportedAsync(string contentType, CancellationToken cancellationToken = default)
Parameters
contentTypestringContent type.
cancellationTokenCancellationTokenCancellation token.
Returns
OptimizeMediaAsync(byte[], string?, string?, ImagePlaceholderAlgorithm, CancellationToken)
Optimizes given source media file.
public Task<FileResult> OptimizeMediaAsync(byte[] contents, string? contentType = null, string? fileName = null, ImagePlaceholderAlgorithm imagePlaceholderAlgorithm = ImagePlaceholderAlgorithm.None, CancellationToken cancellationToken = default)
Parameters
contentsbyte[]File bytes.
contentTypestringFile content type. If not specified, it will be deduced from file signature: however, please specify it if available.
fileNamestringFile name. If not specified, its value will be a random file name compatible with specified (or deduced) content type.
imagePlaceholderAlgorithmImagePlaceholderAlgorithmDesired placeholder generation algorithm. Defaults to None.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<FileResult>
An optimized version of given source media file.
OptimizeMediaAsync(Uri, ImagePlaceholderAlgorithm, CancellationToken)
Optimizes given source media file.
public Task<FileResult> OptimizeMediaAsync(Uri fileUri, ImagePlaceholderAlgorithm imagePlaceholderAlgorithm = ImagePlaceholderAlgorithm.None, CancellationToken cancellationToken = default)
Parameters
fileUriUriSource file URI.
imagePlaceholderAlgorithmImagePlaceholderAlgorithmDesired placeholder generation algorithm. Defaults to None.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<FileResult>
An optimized version of given source media file.