Table of Contents

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 ImagePlaceholderAlgorithm

Desired placeholder generation algorithm.

contentType string

File content type. If not specified, it will be deduced from file signature: however, please specify it if available.

fileName string

File name. If not specified, its value will be a random file name compatible with specified (or deduced) content type.

cancellationToken CancellationToken

Cancellation 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 Uri

Source file URI.

imagePlaceholderAlgorithm ImagePlaceholderAlgorithm

Desired placeholder generation algorithm.

cancellationToken CancellationToken

Cancellation 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 string

File content type. If not specified, it will be deduced from file signature: however, please specify it if available.

fileName string

File name. If not specified, its value will be a random file name compatible with specified (or deduced) content type.

widthPx ushort

Max 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 ushort

Max 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 ushort

Shaves shavePx from source file edges.

fill bool

If 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 bool

Finds a good crop which satisfies specified widthPx and heightPx parameters. When smart crop is enabled, fill is ignored. Defaults to false.

fallback bool

If 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 ImagePlaceholderAlgorithm

Desired placeholder generation algorithm. Defaults to None.

cancellationToken CancellationToken

Cancellation 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 Uri

Source file URI.

widthPx ushort

Max 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 ushort

Max 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 ushort

Shaves shavePx from source file edges.

fill bool

If 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 bool

Finds a good crop which satisfies specified widthPx and heightPx parameters. When smart crop is enabled, fill is ignored. Defaults to false.

fallback bool

If 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 ImagePlaceholderAlgorithm

Desired placeholder generation algorithm. Defaults to None.

cancellationToken CancellationToken

Cancellation 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 CancellationToken

Cancellation token.

Returns

Task<bool>

True if service is healthy, false otherwise.

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 string

Content type.

cancellationToken CancellationToken

Cancellation 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 string

Content type.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<bool>

True if given content type is supported by media file optimization, false otherwise.

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 string

Content type.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<bool>

True if given content type is supported by thumbnail generation, false otherwise.

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 string

File content type. If not specified, it will be deduced from file signature: however, please specify it if available.

fileName string

File name. If not specified, its value will be a random file name compatible with specified (or deduced) content type.

imagePlaceholderAlgorithm ImagePlaceholderAlgorithm

Desired placeholder generation algorithm. Defaults to None.

cancellationToken CancellationToken

Cancellation 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 Uri

Source file URI.

imagePlaceholderAlgorithm ImagePlaceholderAlgorithm

Desired placeholder generation algorithm. Defaults to None.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<FileResult>

An optimized version of given source media file.