Avatar editor
Upload, crop to a square or a circle, resize, and compress to a byte budget. The exported file is WebP where the browser can write it and a fallback otherwise, with every trace of location metadata removed.
Try it
Options
Framing
Smart framing scores detail, colour and skin tones to find the subject, instead of
assuming it is in the middle. Centre-cropping a portrait is how avatars lose the
top of a head.
The pipeline behind this page
A square crop around the subject, a high quality downscale and a gentle sharpen, then an encode that bisects on quality until the file fits the budget. The circular mask is applied to the pixels rather than drawn with CSS, so the exported file is genuinely round - which is also why a circular avatar falls back to PNG rather than JPEG: a format without an alpha channel would show the corners.
// Square crop around the subject, high quality downscale, gentle sharpen,
// then compress until it fits the budget. The circle is a mask on the
// pixels' alpha, so the exported file is round rather than a CSS trick.
var pipeline = ImagePipeline.Create()
.AutoOrient()
.SmartCrop(AspectRatio.Square) // finds the subject instead of assuming the centre
.Resize(size, size, ResizeMode.Stretch)
.Sharpen(amount: 0.25f);
if (circular) pipeline = pipeline.ApplyMask(Mask.Ellipse());
using var avatar = await pipeline.ExecuteAsync(source);
var encoded = await exporter.EncodeWithFallbackAsync(
avatar,
circular ? [ImageFormat.WebP, ImageFormat.Png] : [ImageFormat.WebP, ImageFormat.Jpeg],
new ImageExportOptions
{
Quality = 0.9,
MaxFileSize = budgetKb * 1024,
MinQuality = 0.5,
Metadata = MetadataPolicy.Remove,
Background = Rgba32.White,
});
// The swatches: the photo's main colours, for a placeholder or a profile's accent.
var palette = ImageStatistics.GetDominantColors(source, count: 5, ignoreNearWhiteAndBlack: true);What to take from it
- Frame the subject, not the centre.
SmartCropis a heuristic, not face recognition; if you have a detector, pass its rectangle toSmartCrop.FindCropasmustInclude. - Budget in bytes, not quality.
MaxFileSizereports the quality it settled on, and throwsImageEncodeExceptionrather than handing back an oversized file when the target is impossible. - Remove metadata. An avatar is published to everyone;
MetadataPolicy.Removeis the default for a reason. See Metadata and privacy. - Show something before the image arrives. The swatches are
ImageStatistics.GetDominantColors: the first makes a fitting background for the circle while the file loads, and the headless API goes further with a 67 character blurred placeholder.