Search Results for

Show / Hide Table of Contents

# Interface IImageTransformer

Optional server-side image transformer for URL-based transforms (`?w=&h=&fit=&format=&q=`) produced by `CoreUpload.transformUrl()` on the client.

CoreUpload ships ZERO image-library dependencies to remain cross-platform and trimming-friendly, so this capability is opt-in. Register an implementation in DI to have the download endpoint honor transform query parameters:

    builder.Services.AddSingleton<IImageTransformer, ImageSharpTransformer>();

When no implementation is registered, the download endpoint streams the original bytes and the client / CDN is expected to apply the transform.

###### Namespace: CoreUpload.Providers

###### Assembly: CoreUpload.dll

##### Syntax

    public interface IImageTransformer

### Methods

#### TransformAsync(Stream, IQueryCollection, string?)

Transform the supplied image stream per the request query parameters. Recognized keys: `w`, `h` (pixels), `fit` (cover|contain|inside|outside), `format` (jpeg|webp|avif|png), `q` (1-100), `crop` ('x,y,w,h'), `blur` (radius px), `gravity` (compass|smart|face), `rotate` (90|180|270), `flip` (h|v|hv), `grayscale` (1), `wm` (watermark text) and `wmpos` (compass|center). Use Parse(IQueryCollection) for validated, clamped values instead of re-parsing the raw query. Return `(null, null)` to fall back to the original.

##### Declaration

    Task<(byte[]? Bytes, string? ContentType)> TransformAsync(Stream source, IQueryCollection query, string? sourceContentType)

##### Parameters

Type | Name | Description
--- | --- | ---
Stream | source | The original image stream.
IQueryCollection | query | The request query collection.
string | sourceContentType | The original content type, if known.

##### Returns

Type | Description
--- | ---
Task<(byte[] Bytes, string ContentType)> | The transformed bytes and their content type, or (null, null).