Operations Reference
Complete catalogue of transformations and filters available on ImagePipeline. All operations modify the pipeline in place and return this for chaining.
Transformations
Section titled “Transformations”Resize(width, height, filter)
Section titled “Resize(width, height, filter)”Resize to exact dimensions. Does not preserve aspect ratio — if the ratio differs from the source, the image is stretched.
pipe.Resize(800, 600, ResizeFilter.Lanczos3);ResizeFilter values, in order of quality/cost:
| Filter | When to use |
|---|---|
Nearest | Pixel art, speed-critical paths; fastest |
Triangle | Quick downscale, acceptable quality |
CatmullRom | Good general-purpose, moderate cost |
Mitchell | Smooth downscale |
Gaussian | Soft result, useful for thumbnails |
Lanczos3 | Highest-quality (default) |
Thumbnail(maxWidth, maxHeight, filter)
Section titled “Thumbnail(maxWidth, maxHeight, filter)”Fit the image inside the bounding box while preserving aspect ratio. At most one dimension hits the bound; the other is smaller.
pipe.Thumbnail(400, 400); // fits a 800×600 into 400×300pipe.Thumbnail(400, 400, ResizeFilter.CatmullRom); // faster than Lanczos3If the source is already smaller than the bounds, Thumbnail is a no-op.
Crop(x, y, width, height)
Section titled “Crop(x, y, width, height)”Cut a rectangular region. Coordinates are in pixels from the top-left corner.
pipe.Crop(x: 100, y: 100, width: 400, height: 300);Cropping past the image bounds throws ImagingException { Reason = InvalidArgument }.
Rotate(degrees)
Section titled “Rotate(degrees)”Rotate by 90, 180, or 270 degrees (positive = clockwise). Arbitrary angles are not supported — the native layer only does lossless 90° rotations.
pipe.Rotate(90); // landscape → portraitpipe.Rotate(270); // equivalent to Rotate(-90)Passing any other value throws.
FlipHorizontal() / FlipVertical()
Section titled “FlipHorizontal() / FlipVertical()”Mirror the image along the corresponding axis.
pipe.FlipHorizontal(); // left-right mirrorpipe.FlipVertical(); // top-bottom mirrorFilters
Section titled “Filters”Grayscale()
Section titled “Grayscale()”Convert to luminance-preserving grayscale. The pixel format remains RGB / RGBA — pixels just have equal R=G=B channels.
pipe.Grayscale();Blur(sigma)
Section titled “Blur(sigma)”Gaussian blur. sigma is the standard deviation in pixels; sigma=1.0 is a light blur, 5.0 is heavy.
pipe.Blur(sigma: 2.0f);Sharpen(sigma, threshold)
Section titled “Sharpen(sigma, threshold)”Unsharp-mask sharpening. sigma controls the radius of the underlying blur; threshold is the minimum pixel difference (0-255) that triggers sharpening.
pipe.Sharpen(sigma: 1.0f, threshold: 1); // defaultpipe.Sharpen(sigma: 1.5f, threshold: 3); // stronger, ignores micro-noiseLow threshold sharpens everything (including noise); high threshold preserves smooth areas.
Brightness(value)
Section titled “Brightness(value)”Add or subtract a constant to every RGB channel. Range -128 to +128.
pipe.Brightness(20); // brightenpipe.Brightness(-30); // darkenValues outside the range are clamped native-side.
Contrast(value)
Section titled “Contrast(value)”Multiplicative contrast. 1.0 is identity; >1.0 increases contrast; <1.0 flattens.
pipe.Contrast(1.2f); // 20% more contrastpipe.Contrast(0.8f); // flatterEncoding
Section titled “Encoding”EncodeTo(stream, format, quality)
Section titled “EncodeTo(stream, format, quality)”Serialise the current pipeline state to the stream. Quality ignored for PNG (lossless); applies to JPEG and WebP (0-100).
pipe.EncodeTo(output, ImageFormat.Png);pipe.EncodeTo(output, ImageFormat.Jpeg, quality: 85);pipe.EncodeTo(output, ImageFormat.Webp, quality: 80);Supported output formats: PNG, JPEG, WebP, BMP.
After EncodeTo, the pipeline’s native buffer is released. Call Load again for a fresh pipeline.
Inspection
Section titled “Inspection”ImageInfo.FromBytes(bytes) / FromStream(stream, maxBytes)
Section titled “ImageInfo.FromBytes(bytes) / FromStream(stream, maxBytes)”Parse the format header to read dimensions without a full decode. Returns:
public sealed record ImageInfo( ImageFormat Format, uint Width, uint Height);Header-only parsing means this is cheap — use it to validate uploads before committing to a full ImagePipeline.Load.
QR codes
Section titled “QR codes”QrCode.GeneratePng(text, output, moduleSize, margin)
Section titled “QrCode.GeneratePng(text, output, moduleSize, margin)”Emit a PNG-encoded QR code directly to a stream.
| Parameter | Default | Meaning |
|---|---|---|
text | — | Payload — URL, text, any UTF-8 string |
output | — | Target stream |
moduleSize | 10 | Pixels per QR module |
margin | 2 | Quiet-zone size in modules |
Error correction level is fixed at Medium (automatic from qrcode crate defaults). For other levels or output formats, use a dedicated QR library.
Combining operations
Section titled “Combining operations”Typical transform chains:
// Thumbnail for a gallerypipe.Thumbnail(400, 400, ResizeFilter.CatmullRom) .EncodeTo(out, ImageFormat.Webp, quality: 80);
// Sharpened grayscale scanpipe.Resize(2048, 2048) .Grayscale() .Sharpen(sigma: 1.5f, threshold: 2) .EncodeTo(out, ImageFormat.Png);
// Rotate + crop + re-encodepipe.Rotate(90) .Crop(x: 100, y: 200, width: 600, height: 400) .EncodeTo(out, ImageFormat.Jpeg, quality: 90);Operations are applied in order. Ordering matters: Crop → Resize keeps the crop; Resize → Crop crops from the resized image.
Bulk helpers
Section titled “Bulk helpers”ImageConverter (in Pragmatic.Imaging) provides one-liner helpers that wrap the pipeline:
ImageConverter.ThumbnailAsync(bytes, maxWidth, maxHeight, format, quality, options, ct)ImageConverter.ResizeAsync(bytes, width, height, format, quality, options, ct)ImageConverter.ConvertAsync(bytes, format, quality, options, ct)ImageConverter.StripMetadataAsync(bytes, format, quality, options, ct)
These are convenience wrappers — they open a pipeline, do the operation, encode, and return byte[].
ImageBatch wraps these for concurrent processing of multiple inputs.
What’s not supported
Section titled “What’s not supported”- Arbitrary-angle rotation
- Text overlay / drawing
- Colour-space conversion (sRGB assumed throughout)
- Animation frames (GIF / APNG / animated WebP — first frame only)
- EXIF-preserving operations (EXIF is stripped on re-encode)
- Floating-point pixel formats
- HDR imagery
For any of the above, use ImageSharp or a dedicated tool.
Related
Section titled “Related”- concepts.md — pipeline lifecycle, thread safety, memory model
- native-deployment.md — deploying the native binary