{"record":{"id":"16ccf92c1d7f9fcd","repo":"gchq/CyberChef","slug":"error-adjusting-image-hue-saturation-lightness","errorCode":null,"errorMessage":"Error adjusting image hue / saturation / lightness. (${err})","messagePattern":"Error adjusting image hue / saturation / lightness\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ImageHueSaturationLightness.mjs","lineNumber":115,"sourceCode":"                if (isWorkerEnvironment())\n                    self.sendStatusMessage(\"Changing image lightness...\");\n                image.color([\n                    {\n                        apply: \"lighten\",\n                        params: [lightness],\n                    },\n                ]);\n            }\n\n            let imageBuffer;\n            if (image.mime === \"image/gif\") {\n                imageBuffer = await image.getBuffer(JimpMime.png);\n            } else {\n                imageBuffer = await image.getBuffer(image.mime);\n            }\n            return imageBuffer.buffer;\n        } catch (err) {\n            throw new OperationError(\n                `Error adjusting image hue / saturation / lightness. (${err})`,\n            );\n        }\n    }\n\n    /**\n     * Displays the image using HTML for web apps\n     * @param {ArrayBuffer} data\n     * @returns {html}\n     */\n    present(data) {\n        if (!data.byteLength) return \"\";\n        const dataArray = new Uint8Array(data);\n\n        const type = isImage(dataArray);\n        if (!type) {\n            throw new OperationError(\"Invalid file type.\");\n        }","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ImageHueSaturationLightness.mjs#L97-L133","documentation":"Catches any exception thrown while applying hue/saturation/lightness via image.color/brightness or while getBuffer encodes the result, and re-throws it as an OperationError. GIF outputs are re-encoded as PNG (image.mime === 'image/gif' branch), so encoder errors here usually involve PNG. The interpolated err gives the Jimp-level cause.","triggerScenarios":"Hue/saturation/lightness argument values outside Jimp's accepted numeric ranges, NaN produced by parsing, or getBuffer failing on an output mime Jimp cannot encode. Also fires on internal Jimp failures for very large images or unexpected pixel layouts.","commonSituations":"Argument sliders pushed to non-numeric/extreme values, a corrupted pixel buffer surviving Jimp.read, or memory pressure on a huge image during encode.","solutions":["Clamp hue to [-360,360], saturation/lightness to [-100,100] before calling.","Reduce the image size and retry to rule out memory/timeout.","Re-encode the source to PNG so the GIF-to-PNG output branch is exercised cleanly.","If err names a specific Jimp method, upgrade or pin jimp to a compatible version."],"exampleFix":"// before\nhslOp.run(png, [9999, NaN, -500]); // throws adjusting error\n// after\nconst clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, Number(v) || 0));\nhslOp.run(png, [clamp(hue,-360,360), clamp(sat,-100,100), clamp(light,-100,100)]);","handlingStrategy":"validation","validationCode":"const clamp = (v, lo, hi) => { const n = Number(v); return Number.isFinite(n) ? Math.max(lo, Math.min(hi, n)) : lo; };\nconst safeArgs = [clamp(hue, -360, 360), clamp(sat, -100, 100), clamp(light, -100, 100)];","typeGuard":"function isValidHSLArgs([h, s, l]) {\n  return [h, s, l].every(v => Number.isFinite(Number(v)));\n}","tryCatchPattern":null,"preventionTips":["Coerce and clamp all numeric args before calling.","Reject NaN/empty slider values upstream.","Downscale very large images before encode-heavy ops.","Isolate the processing try/catch so encode failures are surfaced with the Jimp cause."],"tags":["image","jimp","argument-validation","cyberchef","error-handling"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}