Image Formats
ImageSharp keeps the in-memory image model separate from the file format on disk. That means the same processing code can work across JPEG, PNG, WebP, TIFF, OpenEXR, GIF, and the other built-in codecs, while the encoder and metadata layers handle the format-specific details at the edges.
This page is the format map for the library: which built-in formats ship by default, what each one is good at, and where to go next for format-specific guidance.
Format, Codec, and Pixel Type
These terms refer to different parts of the imaging pipeline:
- A file format is the encoded representation on disk or in a stream, such as JPEG, PNG, WebP, or TIFF.
- A decoder reads encoded data from a file format and produces an
ImageorImage<TPixel>. - An encoder writes an image back to a chosen file format.
- A pixel type, such as
Rgba32, describes the in-memory representation used while the image is loaded and processed. - Metadata describes information carried alongside the pixels, such as orientation, ICC profiles, frame timing, comments, and format-specific tags.
Changing the file format is not the same operation as changing the in-memory pixel type. Saving an Image<Rgba32> as JPEG writes JPEG-encoded data from RGBA pixels; loading a PNG as Image<L8> converts decoded image samples into an 8-bit luminance pixel buffer. Metadata handling is a separate concern again, controlled by decoder and encoder options.
What a Format Decides
An image file format is not only a filename extension. It defines which image information can be represented and how that information is stored. The important questions are:
- Is the encoded pixel data compressed, and is that compression lossy or lossless?
- Which color models, bit depths, and component precisions can the format represent?
- Can the format store alpha transparency, and if so is it full alpha or index-based transparency?
- Can the format store multiple frames, animation timing, blending, and disposal behavior?
- Which metadata can be represented, such as EXIF, ICC profiles, text chunks, frame metadata, or format-specific tags?
- Which applications, browsers, operating systems, and asset pipelines need to read the output?
These questions are why there is no universal "best" image format. JPEG, PNG, GIF, WebP, TIFF, and OpenEXR are not interchangeable containers with different extensions; they preserve and discard different parts of the image model.
Delivery, Interchange, and Working Formats
Many format decisions become clearer when you separate the job the file has to do:
- Delivery formats prioritize compatibility, size, and decode behavior for the consuming client. JPEG, PNG, GIF, and WebP are common examples.
- Interchange formats preserve information for another tool or workflow. TIFF, OpenEXR, TGA, BMP, QOI, and Netpbm-style formats can be useful here depending on the pipeline.
- Working formats are the files you keep before final export. They may be larger or richer than the public output because they need to preserve editability, metadata, precision, layers in another application, or a lossless source for later conversions.
ImageSharp works with raster images. Vector artwork, document formats, and application-native design files are outside the built-in codec set, although you can render or import them through other tools before handing raster pixels to ImageSharp.
Compression and Re-encoding
Lossless formats preserve the decoded pixel values exactly, subject to the color and pixel representation chosen by the encoder. PNG, QOI, lossless WebP, and many TIFF configurations fall into this category.
Lossy formats intentionally discard information to reduce file size. JPEG and lossy WebP are useful because the loss is often acceptable for photographs, but re-encoding lossy inputs can compound artifacts. Converting a JPEG to PNG does not restore detail that the JPEG encoder already removed; it only stores the current decoded pixels losslessly.
Some formats can be either lossy or lossless depending on encoder settings. WebP and TIFF are format families with multiple encoding modes, so the encoder configuration matters as much as the extension.
Built-In Formats
The source of truth for the built-in format list is Configuration: the default ImageSharp configuration preregisters encoder, decoder, and detector modules for the following public IImageFormat types:
| Format | Public API type | Built in by default |
|---|---|---|
| BMP | BmpFormat |
Read and write |
| CUR | CurFormat |
Read and write |
| EXR | ExrFormat |
Read and write |
| GIF | GifFormat |
Read and write |
| ICO | IcoFormat |
Read and write |
| JPEG | JpegFormat |
Read and write |
| PBM | PbmFormat |
Read and write |
| PNG | PngFormat |
Read and write |
| QOI | QoiFormat |
Read and write |
| TGA | TgaFormat |
Read and write |
| TIFF | TiffFormat |
Read and write |
| WebP | WebpFormat |
Read and write |
ICO and CUR are distinct built-in formats even though detection is handled by a shared icon detector internally.
At a Glance
If you only need a quick rule of thumb:
- JPEG is the usual choice for photos when small files matter and transparency does not.
- PNG is the usual choice for lossless graphics, screenshots, and transparency.
- GIF is mainly useful for simple palette-based animation and legacy compatibility.
- WebP covers lossy, lossless, transparency, and animation in one format family.
- TIFF is primarily for archival, print, interchange, and imaging-pipeline workflows.
- OpenEXR is the format to consider for HDR and higher-precision imaging pipelines.
Another way to think about it:
- Lossy formats: JPEG, lossy WebP.
- Lossless formats: PNG, lossless WebP, TIFF, QOI, BMP.
- Higher-precision and HDR workflows: OpenEXR and TIFF.
- Transparency-friendly formats: PNG, WebP, TIFF, TGA, QOI.
- Animation-friendly formats: GIF, animated PNG workflows through
PngEncoder, and animated WebP.
No single format is best everywhere. The right choice depends on whether your priority is fidelity, file size, transparency, animation, compatibility, or workflow metadata.
When the output crosses a boundary you do not control, compatibility usually outranks theoretical capability. A format can support a feature and still be a poor choice if the receiving client, CDN, print tool, browser, or asset pipeline handles that feature inconsistently.
Load, Detect, and Preserve Formats
Image<TPixel> represents decoded pixel data. Once an image is loaded into memory, it is no longer tied to a specific file format unless you explicitly inspect or preserve that information.
ImageSharp can detect the encoded format of a source before loading it with Image.DetectFormat():
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;
IImageFormat format = Image.DetectFormat("input.bin");
Console.WriteLine(format.Name);
Decoded images also keep the original format in ImageMetadata.DecodedImageFormat.
That metadata is useful when you want to explicitly save back to the originally decoded format, especially when writing to a stream where there is no file extension to select an encoder for you:
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using Image image = Image.Load("input.jpg");
image.Mutate(x => x.Resize(1200, 800));
if (image.Metadata.DecodedImageFormat is not null)
{
using FileStream outputStream = File.Create("output.jpg");
image.Save(outputStream, image.Metadata.DecodedImageFormat);
}
When you save by path, image.Save("output.jpg") or image.Save("output.png") selects the encoder from the destination file extension.
You can also choose a format explicitly by passing an encoder or by using the SaveAs...() helpers.
Save with Explicit Encoders
ImageEncoder implementations are lightweight configuration objects. Create one when you want to control how a format is written:
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Png;
using Image image = Image.Load("input.png");
image.Save("output.jpg", new JpegEncoder { Quality = 85 });
image.Save("output.png", new PngEncoder());
ImageSharp also provides format-specific helpers:
image.SaveAsBmp()usesBmpEncoder.image.SaveAsCur()usesCurEncoder.image.SaveAsExr()usesExrEncoder.image.SaveAsGif()usesGifEncoder.image.SaveAsIco()usesIcoEncoder.image.SaveAsJpeg()usesJpegEncoder.image.SaveAsPbm()usesPbmEncoder.image.SaveAsPng()usesPngEncoder.image.SaveAsQoi()usesQoiEncoder.image.SaveAsTga()usesTgaEncoder.image.SaveAsTiff()usesTiffEncoder.image.SaveAsWebp()usesWebpEncoder.
General Decoder Options
Use DecoderOptions with the general Load() APIs when you want to control metadata handling, frame limits, or decode-to-size behavior:
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;
DecoderOptions options = new()
{
MaxFrames = 1,
SkipMetadata = false,
TargetSize = new Size(1600, 1600)
};
using Image image = Image.Load(options, "input.webp");
Format-specific decoder option types also exist for specialized scenarios such as JPEG and PNG.
Common Encoder Families
Several formats share useful option sets through common encoder base types:
ImageEncoderexposesSkipMetadata.AlphaAwareImageEncoderaddsTransparentColorMode.QuantizingImageEncoderaddsQuantizerandPixelSamplingStrategy.AnimatedImageEncoderaddsRepeatCount,BackgroundColor, andAnimateRootFrame.
Those inherited options are especially useful when working with GIF, APNG, and animated WebP. For a format-agnostic guide to palettes and dithered output, see Quantization, Palettes, and Dithering.
Format Guides
Use the format-specific guides for the common cases and specialized workflows:
- JPEG for photographic output and quality-focused lossy compression.
- PNG for lossless output, transparency, and APNG metadata.
- GIF for palette-based animation workflows.
- WebP for lossy, lossless, transparent, and animated WebP output.
- TIFF for workflows where compression mode, pixel layout, and TIFF metadata matter.
- OpenEXR for HDR and higher-precision imaging workflows.
The less commonly used built-in formats still have valid niches:
- BMP is simple and broadly understood, but usually much larger than modern alternatives.
- ICO stores Windows icon files, often with one or more embedded icon images.
- CUR stores Windows cursor files and hotspot metadata.
- PBM covers PBM/PGM/PPM-style Netpbm-family workflows and simple interchange scenarios.
- TGA appears most often in graphics and content-pipeline tooling.
- QOI is a fast, simple lossless format with a much smaller ecosystem than PNG or WebP.
Custom Format Registration
Format detectors, decoders, and encoders are registered through ImageSharp configuration. See Configuration if you need to customize the set of supported formats for your application.
Choosing the Right Encoder
The right encoder settings depend on the tradeoff you want to make between:
- Image file size
- Encoder speed
- Image quality
The format-specific pages below are the best place to start when you need to tune those tradeoffs.
Practical Guidance
- Use explicit encoders when output behavior matters; file extensions are convenient but hide important defaults.
- Inspect the source with
Identify(...)before conversion when alpha, animation, bit depth, or metadata changes the output decision. - Treat metadata as part of format conversion: orientation, ICC profiles, animation timing, and comments may or may not survive a target format.
- Register only the formats your application needs when you want a smaller or more controlled decoding surface.