{"record":{"id":"1d30166a60dcb82d","repo":"d2phap/ImageGlass","slug":"ige-002","errorCode":"IGE_002","errorMessage":"IGE_002: Unsupported image format.","messagePattern":"IGE_002: Unsupported image format\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"warning","filePath":"source/ImageGlass.Lib/Common/Photoing/Codecs/MagickCodecs/MagickCodec.cs","lineNumber":1284,"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}\n\n","sourceCodeStart":1266,"sourceCodeEnd":1291,"githubUrl":"https://github.com/d2phap/ImageGlass/blob/4a3c4feceffc5a8bb5e56ba836509634aaae47a9/source/ImageGlass.Lib/Common/Photoing/Codecs/MagickCodecs/MagickCodec.cs#L1266-L1291","documentation":"Thrown by MagickCodec.LosslessCompress when Magick.NET's ImageOptimizer does not support the file. ImageOptimizer only losslessly rewrites a small set of formats (primarily JPEG and PNG); IsSupported returns false for everything else and the method throws NotSupportedException tagged IGE_002. A null/blank path returns false earlier instead of throwing.","triggerScenarios":"Calling LosslessCompress on a GIF, WEBP, BMP, TIFF, HEIC, RAW, SVG, or any format outside the optimizer's supported set; running the built-in LosslessCompression tool on a mixed batch without filtering.","commonSituations":"Batch compression tool invoked on a folder containing animation/image formats the optimizer cannot touch; user expects 'lossless compress' to apply to every image type; plugin-owned format passed to the built-in compressor.","solutions":["Pre-check support the same way the method does: if (new ImageOptimizer().IsSupported(new FileInfo(path))) before calling, and skip otherwise.","Filter batch inputs to JPEG/PNG before invoking LosslessCompress.","Wrap the call in try/catch (NotSupportedException) and continue the batch instead of aborting.","For unsupported formats, fall back to a lossy re-encode via MagickCodec.SaveAsync if compression is mandatory."],"exampleFix":"// before\nMagickCodec.LosslessCompress(filePath);\n\n// after\nvar opt = new ImageOptimizer { OptimalCompression = true };\nif (opt.IsSupported(new FileInfo(filePath)))\n{\n    MagickCodec.LosslessCompress(filePath);\n}","handlingStrategy":"validation","validationCode":"var fi = new FileInfo(filePath);\nvar supported = new ImageOptimizer { OptimalCompression = true }.IsSupported(fi);\nif (!supported) return; // skip silently","typeGuard":null,"tryCatchPattern":"try { MagickCodec.LosslessCompress(filePath); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"IGE_002\"))\n{ /* skip unsupported file in a batch */ }","preventionTips":["Pre-filter batch inputs to JPEG/PNG, the formats ImageOptimizer supports.","Mirror the IsSupported check the method uses before calling.","Treat NotSupported as 'skip and continue' in batch tools, not as fatal."],"tags":["codec","magick","compression","format"],"backgroundTag":null,"analyzedSha":"4a3c4feceffc5a8bb5e56ba836509634aaae47a9","analyzedAt":"2026-08-13T16:58:15.523Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}