d2phap/ImageGlass · error · NotSupportedException

IGE_002

IGE_002

Error message

IGE_002: Unsupported image format.

What it means

Thrown by PhotoCodec.LosslessCompress (v9) when Magick.NET's ImageOptimizer.IsSupported(file) returns false. ImageOptimizer performs lossless recompression and only supports a small set — primarily JPEG, PNG, and certain animated/still formats the library was built to optimize. Any other extension (or a supported extension whose content ImageOptimizer rejects) triggers NotSupportedException with code IGE_002.

Source

Thrown at v9/Components/ImageGlass.Base/Photoing/Codecs/PhotoCodec.cs:816

    /// <summary>
    /// Performs lossless compression on the specified file using Magick.NET.
    /// If the new file size is not smaller, the file won't be overwritten.
    /// </summary>
    /// <returns>True when the image could be compressed otherwise false.</returns>
    /// <exception cref="NotSupportedException"></exception>
    public static bool LosslessCompress(string? filePath)
    {
        if (string.IsNullOrWhiteSpace(filePath)) return false;

        var fi = new FileInfo(filePath);
        var opt = new ImageOptimizer()
        {
            OptimalCompression = true,
        };

        // check if the format is supported
        if (!opt.IsSupported(fi)) throw new NotSupportedException("IGE_002: Unsupported image format.");

        return opt.LosslessCompress(fi);
    }

    #endregion // Public functions



    #region Private functions

    /// <summary>
    /// Checks if the image data is animated format.
    /// </summary>
    /// <param name="imgC"></param>
    /// <param name="ext">File extension, e.g: <c>.gif</c></param>
    private static bool CheckAnimatedFormat(MagickImageCollection imgC, string? ext)
    {
        var isAnimatedExtension = ext == ".GIF" || ext == ".GIFV" || ext == ".WEBP" || ext == ".JXL";

View on GitHub (pinned to 4a3c4fecef)

Solutions

  1. Pre-filter files to ImageOptimizer-supported extensions (jpg/jpeg/png) before calling LosslessCompress; disable the action in the UI for other formats.
  2. Probe with a throwaway 'new ImageOptimizer().IsSupported(new FileInfo(path))' check before invoking and skip (or lossy-compress) unsupported ones.
  3. Update Magick.NET to a build that supports more optimization targets if applicable.
  4. Catch NotSupportedException and report which file/format was skipped rather than aborting the whole batch.

Example fix

// before
PhotoCodec.LosslessCompress(path);

// after: only attempt supported formats
var opt = new ImageOptimizer { OptimalCompression = true };
if (opt.IsSupported(new FileInfo(path)))
    opt.LosslessCompress(new FileInfo(path));
Defensive patterns

Strategy: validation

Validate before calling

// Only lossless-compress formats ImageOptimizer supports.
var opt = new ImageOptimizer { OptimalCompression = true };
var fi = new FileInfo(filePath);
if (!opt.IsSupported(fi)) return false; // skip unsupported formats

Try / catch

try { PhotoCodec.LosslessCompress(filePath); }
catch (NotSupportedException ex) when (ex.Message.Contains("IGE_002"))
{ /* ImageOptimizer cannot losslessly compress this format */ }

Prevention

When it happens

Trigger: Running lossless compression on a GIF, BMP, TIFF, WEBP, HEIC, raw-camera file, or any format ImageOptimizer does not handle; pointing LosslessCompress at a file whose extension is unrecognized.

Common situations: User selects a batch of mixed formats and the tool calls LosslessCompress on every file; a format the UI advertises as 'compressible' that ImageOptimizer actually rejects; a build of Magick.NET without optimization delegates.

Related errors


AI-assisted analysis of d2phap/ImageGlass@4a3c4fecef (2026-08-13). Data as JSON: /api/errors/3f1e91d7cc39a3ec. Report an issue: GitHub.