{"record":{"id":"3bfe0d61531b3782","repo":"langgenius/dify","slug":"could-not-create-a-canvas-context","errorCode":null,"errorMessage":"Could not create a canvas context","messagePattern":"Could not create a canvas context","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web/app/components/base/app-icon-picker/utils.ts","lineNumber":58,"sourceCode":"  }\n}\n\n/**\n * This function was adapted from the one in the ReadMe of https://github.com/DominicTobias/react-image-crop\n */\nexport default async function getCroppedImg(\n  imageSrc: string,\n  pixelCrop: { x: number; y: number; width: number; height: number },\n  fileName: string,\n  rotation = 0,\n  flip = { horizontal: false, vertical: false },\n): Promise<Blob> {\n  const image = await createImage(imageSrc)\n  const canvas = document.createElement('canvas')\n  const ctx = canvas.getContext('2d')\n  const mimeType = getMimeType(fileName)\n\n  if (!ctx) throw new Error('Could not create a canvas context')\n\n  const rotRad = getRadianAngle(rotation)\n\n  // calculate bounding box of the rotated image\n  const { width: bBoxWidth, height: bBoxHeight } = rotateSize(image.width, image.height, rotation)\n\n  // set canvas size to match the bounding box\n  canvas.width = bBoxWidth\n  canvas.height = bBoxHeight\n\n  // translate canvas context to a central location to allow rotating and flipping around the center\n  ctx.translate(bBoxWidth / 2, bBoxHeight / 2)\n  ctx.rotate(rotRad)\n  ctx.scale(flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1)\n  ctx.translate(-image.width / 2, -image.height / 2)\n\n  // draw rotated image\n  ctx.drawImage(image, 0, 0)","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/web/app/components/base/app-icon-picker/utils.ts#L40-L76","documentation":"Error \"Could not create a canvas context\" thrown in langgenius/dify.","triggerScenarios":"Thrown at web/app/components/base/app-icon-picker/utils.ts:58 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}