SixLabors/ImageSharp · error · ImageFormatException

Image is too large to encode at

Error message

Image is too large to encode at {width}x{height} for WEBP format.

What it means

WebpThrowHelper.ThrowDimensionsTooLarge throws ImageFormatException when encoding a WebP image whose width or height exceeds the WebP format limit (16383x16383, since VP8L/VP8X dimension fields are 14 bits). The message reports the offending width x height. The decoder cannot represent larger images in WebP.

Solutions

  1. Resize the image to <= 16383x16383 before encoding (image.Mutate(x => x.Resize(...))).
  2. Tile the image into multiple WebP files each within the limit.
  3. Choose a different format without this limit (PNG, JPEG, TIFF) for oversized images.
  4. Add a pre-flight check using image.Width/image.Height against the limit and fail fast with a clear message.

Example fix

// before
image.SaveAsWebp("huge.webp"); // throws if > 16383px
// after
if (image.Width > 16383 || image.Height > 16383)
{
    image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2));
}
image.SaveAsWebp("huge.webp");
Defensive patterns

Strategy: validation

Validate before calling

if (image.Width > 16383 || image.Height > 16383)
    image.Mutate(x => x.Resize(new ResizeOptions { Mode = ResizeMode.Max, Size = new(16383, 16383) }));

Type guard

static bool FitsWebpLimits(int width, int height) => (uint)width <= 16383u && (uint)height <= 16383u;

Try / catch

try { image.SaveAsWebp(path); }
catch (ImageFormatException ex) when (ex.Message.Contains("too large")) { /* resize and retry */ }

Prevention

When it happens

Trigger: Calling SaveAsWebp (or the WebpEncoder) on an image larger than 16383 pixels in either dimension; also hit when downscaled animation frames still exceed the limit.

Common situations: Encoding stitched panoramas, high-res scans, or large satellite/medical imagery directly to WebP; pipelines that crop after encoding rather than before.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13). Data as JSON: /api/errors/d22d66ca25e35c00. Report an issue: GitHub.

Appendix: source

Thrown at src/ImageSharp/Formats/Webp/WebpThrowHelper.cs:23

namespace SixLabors.ImageSharp.Formats.Webp;

internal static class WebpThrowHelper
{
    [DoesNotReturn]
    public static void ThrowInvalidImageContentException(string errorMessage) => throw new InvalidImageContentException(errorMessage);

    [DoesNotReturn]
    public static void ThrowImageFormatException(string errorMessage) => throw new ImageFormatException(errorMessage);

    [DoesNotReturn]
    public static void ThrowNotSupportedException(string errorMessage) => throw new NotSupportedException(errorMessage);

    [DoesNotReturn]
    public static void ThrowInvalidImageDimensions(string errorMessage) => throw new InvalidImageContentException(errorMessage);

    [DoesNotReturn]
    public static void ThrowDimensionsTooLarge(int width, int height) => throw new ImageFormatException($"Image is too large to encode at {width}x{height} for WEBP format.");
}

View on GitHub (pinned to 59ce6af6fc)