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
- Resize the image to <= 16383x16383 before encoding (image.Mutate(x => x.Resize(...))).
- Tile the image into multiple WebP files each within the limit.
- Choose a different format without this limit (PNG, JPEG, TIFF) for oversized images.
- 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
- Pre-check dimensions against 16383 before every WebP encode
- Tile or downsize large imagery in the pipeline
- Pick another format for oversized assets
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
- Not supported encoder compression method
- ICO and CUR resources cannot contain more than 65535…
- The icon encoding dimensions exceed the source frame…
- Quality factor must be in [1..100] range.
- Progressive scans must be in [2..64] range.
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)