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
clientConfiguration
IOptions<ThumbnailerClientConfiguration>Thumbnailer client configuration.
logger
ILogger<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
contents
byte[]File bytes.
imagePlaceholderAlgorithm
ImagePlaceholderAlgorithmDesired placeholder generation algorithm.
contentType
stringFile content type. If not specified, it will be deduced from file signature: however, please specify it if available.
fileName
stringFile name. If not specified, its value will be a random file name compatible with specified (or deduced) content type.
cancellationToken
CancellationTokenCancellation 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
fileUri
UriSource file URI.
imagePlaceholderAlgorithm
ImagePlaceholderAlgorithmDesired placeholder generation algorithm.
cancellationToken
CancellationTokenCancellation token.
Returns
- Task<ImagePlaceholderResult>
A very compact representation of given source image.
GenerateThumbnailAsync(byte[], string?, string?, ushort, ushort, ushort, bool, bool, bool, ImagePlaceholderAlgorithm, 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, CancellationToken cancellationToken = default)
Parameters
contents
byte[]File bytes.
contentType
stringFile content type. If not specified, it will be deduced from file signature: however, please specify it if available.
fileName
stringFile name. If not specified, its value will be a random file name compatible with specified (or deduced) content type.
widthPx
ushortMax thumbnail width. Thumbnail will be generated preserving the source file aspect ratio and, if
fill
is true, a transparent background will be added so that thumbnail width and height are exactly as requested.heightPx
ushortMax thumbnail height. Thumbnail will be generated preserving the source file aspect ratio and, if
fill
is true, a transparent background will be added so that thumbnail width and height are exactly as requested.shavePx
ushortShaves
shavePx
from source file edges.fill
boolIf true, a transparent background will be added so that thumbnail width and height are exactly as requested, preserving source file aspect ratio. When
smartCrop
is enabled, this parameter will be ignored. Defaults to true.smartCrop
boolFinds a good crop which satisfies specified
widthPx
andheightPx
parameters. When smart crop is enabled,fill
is ignored. Defaults to false.fallback
boolIf 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.
imagePlaceholderAlgorithm
ImagePlaceholderAlgorithmDesired placeholder generation algorithm. Defaults to None.
cancellationToken
CancellationTokenCancellation token.
Returns
- Task<FileResult>
A thumbnail of given source file.
GenerateThumbnailAsync(Uri, ushort, ushort, ushort, bool, bool, bool, ImagePlaceholderAlgorithm, 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, CancellationToken cancellationToken = default)
Parameters
fileUri
UriSource file URI.
widthPx
ushortMax thumbnail width. Thumbnail will be generated preserving the source file aspect ratio and, if
fill
is true, a transparent background will be added so that thumbnail width and height are exactly as requested.heightPx
ushortMax thumbnail height. Thumbnail will be generated preserving the source file aspect ratio and, if
fill
is true, a transparent background will be added so that thumbnail width and height are exactly as requested.shavePx
ushortShaves
shavePx
from source file edges.fill
boolIf true, a transparent background will be added so that thumbnail width and height are exactly as requested, preserving source file aspect ratio. When
smartCrop
is enabled, this parameter will be ignored. Defaults to true.smartCrop
boolFinds a good crop which satisfies specified
widthPx
andheightPx
parameters. When smart crop is enabled,fill
is ignored. Defaults to false.fallback
boolIf 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.
imagePlaceholderAlgorithm
ImagePlaceholderAlgorithmDesired placeholder generation algorithm. Defaults to None.
cancellationToken
CancellationTokenCancellation 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
cancellationToken
CancellationTokenCancellation 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
contentType
stringContent type.
cancellationToken
CancellationTokenCancellation 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
contentType
stringContent type.
cancellationToken
CancellationTokenCancellation 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
contentType
stringContent type.
cancellationToken
CancellationTokenCancellation 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
contents
byte[]File bytes.
contentType
stringFile content type. If not specified, it will be deduced from file signature: however, please specify it if available.
fileName
stringFile name. If not specified, its value will be a random file name compatible with specified (or deduced) content type.
imagePlaceholderAlgorithm
ImagePlaceholderAlgorithmDesired placeholder generation algorithm. Defaults to None.
cancellationToken
CancellationTokenCancellation 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
fileUri
UriSource file URI.
imagePlaceholderAlgorithm
ImagePlaceholderAlgorithmDesired placeholder generation algorithm. Defaults to None.
cancellationToken
CancellationTokenCancellation token.
Returns
- Task<FileResult>
An optimized version of given source media file.