{"record":{"id":"b386f26b6fca72ec","repo":"gchq/CyberChef","slug":"error-flipping-image-err","errorCode":null,"errorMessage":"Error flipping image. (${err})","messagePattern":"Error flipping image\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/FlipImage.mjs","lineNumber":83,"sourceCode":"                    });\n                    break;\n                case \"Vertical\":\n                    image.flip({\n                        horizontal: false,\n                        vertical: true,\n                    });\n                    break;\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(`Error flipping image. (${err})`);\n        }\n    }\n\n    /**\n     * Displays the flipped 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        }\n\n        return `<img src=\"data:${type};base64,${toBase64(dataArray)}\">`;","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/FlipImage.mjs#L65-L101","documentation":"Thrown when either the flip transformation or the subsequent getBuffer encoding throws inside the second try block. This is a catch-all for errors during image processing/encoding after successful load. The original error is interpolated for diagnostics. It is rarer than the load error because the image already decoded successfully.","triggerScenarios":"Jimp's flip() failing on an edge-case image (e.g. 0-width/0-height after some prior op); getBuffer() failing to re-encode into the target mime (e.g. GIF re-encoded as PNG via JimpMime.png); an out-of-memory or internal Jimp error during buffer serialization.","commonSituations":"Extremely large images exhausting memory during encode; unusual color modes or bit depths Jimp cannot re-encode; a Jimp version regression in getBuffer for a specific mime.","solutions":["Read the interpolated err to pinpoint whether flip() or getBuffer() failed.","If memory-bound, downscale or crop the image before flipping.","Re-save the source in a simpler format (plain PNG/JPEG) to avoid exotic color modes."],"exampleFix":"// before: huge image causing encode failure\nflip.run(hugeBuffer, ['Horizontal'])\n// after: reduce size first, then flip\nconst smaller = await resize.run(hugeBuffer, [800, 600]);\nflip.run(smaller, ['Horizontal'])","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await flip.run(input, args);\n} catch (e) {\n  if (e.type === 'OperationError' && /Error flipping image/.test(e.message)) {\n    // processing/encoding failed; read the interpolated err and downscale/retry\n  } else throw e;\n}","preventionTips":["Downscale very large images before flipping to avoid memory issues.","Normalize exotic color modes to standard PNG/JPEG first.","Inspect the wrapped Jimp error text to choose the right remediation."],"tags":["image","jimp","encode","memory","processing"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}