SixLabors/ImageSharp · error · InvalidImageContentException
Invalid TIFF photometric interpretation for JPEG encoding
Error message
Invalid TIFF photometric interpretation for JPEG encoding: {interpretation} What it means
When decoding a JPEG-compressed TIFF, TiffJpegSpectralConverter maps the TIFF photometric interpretation tag to a JpegColorSpace. Only RGB, Separated (CMYK/Ycck), and YCbCr are handled; any other interpretation (e.g. WhiteIsZero, BlackIsZero, Palette, TransparencyMask) is invalid for JPEG-in-TIFF and throws InvalidImageContentException.
Solutions
- Fix the source file's photometric interpretation tag to match its JPEG data (usually YCbCr or RGB) using tiffset.
- Re-save the TIFF with a conforming encoder (libtiff, ImageMagick) using JPEG compression.
- Catch InvalidImageContentException and fall back to another decoder that tolerates the tag mismatch.
Example fix
// before // file has Compression=JPEG but PhotometricInterpretation=MinIsWhite // after (shell): tiffset -s 262 1 broken.tif # set photometric to BlackIsZero-compatible/YCbCr // or re-encode: // magick broken.tif -compress jpeg fixed.tif
Defensive patterns
Strategy: validation
Try / catch
try { using var img = Image.Load(path); }
catch (InvalidImageContentException ex)
{
// photometric tag incompatible with JPEG compression; repair with tiffset -s 262 <n>
} Prevention
- Inspect photometric tag (tiffinfo) for JPEG-compressed TIFFs before ingesting
- Re-save files from non-conforming encoders with libtiff/ImageMagick
- Treat tag mismatches as source-file bugs — fix at the producer
When it happens
Trigger: Image.Load/opening of a TIFF with Compression=JPEG whose PhotometricInterpretation tag is one of the unsupported values (WhiteIsZero, BlackIsZero, Palette, Mask).
Common situations: Hand-edited or buggy encoder output where the JPEG-compressed TIFF carries a mismatched photometric tag; corrupted tag values in legacy files.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Invalid tiff photometric interpretation for jpeg encoding
- Bad sampling factor
- Invalid progressive parameters Ss=
- Invalid image dimensions
- Images with components are not supported.
AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13).
Data as JSON: /api/errors/54295ad8b7f75177.
Report an issue: GitHub.
Appendix: source
Thrown at src/ImageSharp/Formats/Tiff/Compression/Decompressors/TiffJpegSpectralConverter{TPixel}.cs:58
/// The color conversion will be done after the decompression. For Separated/CMYK/YCCK, the jpeg color converter will handle the color conversion,
/// since the jpeg color converter needs to return RGB data and cannot return 4 component data.
/// For grayscale images <see cref="GrayJpegSpectralConverter{TPixel}"/> must be used.
/// </summary>
/// <param name="interpretation">
/// The <see cref="TiffPhotometricInterpretation"/> to convert to a <see cref="JpegColorSpace"/>.
/// </param>
/// <param name="data">
/// The <see cref="IRawJpegData"/> containing the color space information.
/// </param>
/// <exception cref="InvalidImageContentException">
/// Thrown when the <paramref name="interpretation"/> is not supported for JPEG encoding.
/// </exception>
private static JpegColorSpace GetJpegColorSpace(TiffPhotometricInterpretation interpretation, IRawJpegData data) => interpretation switch
{
TiffPhotometricInterpretation.Rgb => JpegColorSpace.RGB,
TiffPhotometricInterpretation.Separated => data.ColorSpace == JpegColorSpace.Ycck ? JpegColorSpace.TiffYccK : JpegColorSpace.TiffCmyk,
TiffPhotometricInterpretation.YCbCr => JpegColorSpace.RGB, // TODO: Why doesn't this use the YCbCr color space?
_ => throw new InvalidImageContentException($"Invalid TIFF photometric interpretation for JPEG encoding: {interpretation}"),
};
}
View on GitHub (pinned to 59ce6af6fc)