{"record":{"id":"3f1e91d7cc39a3ec","repo":"d2phap/ImageGlass","slug":"ige-002-3f1e91","errorCode":"IGE_002","errorMessage":"IGE_002: Unsupported image format.","messagePattern":"IGE_002: Unsupported image format\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"v9/Components/ImageGlass.Base/Photoing/Codecs/PhotoCodec.cs","lineNumber":816,"sourceCode":"\n    /// <summary>\n    /// Performs lossless compression on the specified file using Magick.NET.\n    /// If the new file size is not smaller, the file won't be overwritten.\n    /// </summary>\n    /// <returns>True when the image could be compressed otherwise false.</returns>\n    /// <exception cref=\"NotSupportedException\"></exception>\n    public static bool LosslessCompress(string? filePath)\n    {\n        if (string.IsNullOrWhiteSpace(filePath)) return false;\n\n        var fi = new FileInfo(filePath);\n        var opt = new ImageOptimizer()\n        {\n            OptimalCompression = true,\n        };\n\n        // check if the format is supported\n        if (!opt.IsSupported(fi)) throw new NotSupportedException(\"IGE_002: Unsupported image format.\");\n\n        return opt.LosslessCompress(fi);\n    }\n\n    #endregion // Public functions\n\n\n\n    #region Private functions\n\n    /// <summary>\n    /// Checks if the image data is animated format.\n    /// </summary>\n    /// <param name=\"imgC\"></param>\n    /// <param name=\"ext\">File extension, e.g: <c>.gif</c></param>\n    private static bool CheckAnimatedFormat(MagickImageCollection imgC, string? ext)\n    {\n        var isAnimatedExtension = ext == \".GIF\" || ext == \".GIFV\" || ext == \".WEBP\" || ext == \".JXL\";","sourceCodeStart":798,"sourceCodeEnd":834,"githubUrl":"https://github.com/d2phap/ImageGlass/blob/4a3c4feceffc5a8bb5e56ba836509634aaae47a9/v9/Components/ImageGlass.Base/Photoing/Codecs/PhotoCodec.cs#L798-L834","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pre-filter files to ImageOptimizer-supported extensions (jpg/jpeg/png) before calling LosslessCompress; disable the action in the UI for other formats.","Probe with a throwaway 'new ImageOptimizer().IsSupported(new FileInfo(path))' check before invoking and skip (or lossy-compress) unsupported ones.","Update Magick.NET to a build that supports more optimization targets if applicable.","Catch NotSupportedException and report which file/format was skipped rather than aborting the whole batch."],"exampleFix":"// before\nPhotoCodec.LosslessCompress(path);\n\n// after: only attempt supported formats\nvar opt = new ImageOptimizer { OptimalCompression = true };\nif (opt.IsSupported(new FileInfo(path)))\n    opt.LosslessCompress(new FileInfo(path));","handlingStrategy":"validation","validationCode":"// Only lossless-compress formats ImageOptimizer supports.\nvar opt = new ImageOptimizer { OptimalCompression = true };\nvar fi = new FileInfo(filePath);\nif (!opt.IsSupported(fi)) return false; // skip unsupported formats","typeGuard":null,"tryCatchPattern":"try { PhotoCodec.LosslessCompress(filePath); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"IGE_002\"))\n{ /* ImageOptimizer cannot losslessly compress this format */ }","preventionTips":["Pre-filter batches to JPEG/PNG (ImageOptimizer's main targets).","Disable the lossless-compress action in the UI for unsupported formats.","Probe IsSupported before calling; skip rather than throw."],"tags":["magick-net","image-format","compression","codec","notsupportedexception","imageglass","v9"],"backgroundTag":null,"analyzedSha":"4a3c4feceffc5a8bb5e56ba836509634aaae47a9","analyzedAt":"2026-08-13T16:58:15.523Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}