{"record":{"id":"17333b392c4938d3","repo":"phacility/phabricator","slug":"unable-to-imagecolorallocatealpha-a-new-empty-im","errorCode":null,"errorMessage":"Unable to imagecolorallocatealpha() a new empty image: %s","messagePattern":"Unable to imagecolorallocatealpha\\(\\) a new empty image: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/files/transform/PhabricatorFileImageTransform.php","lineNumber":198,"sourceCode":"    }\n\n    $trap = new PhutilErrorTrap();\n    $ok = @imagesavealpha($img, true);\n    $errors = $trap->getErrorsAsString();\n    $trap->destroy();\n    if ($ok === false) {\n      throw new Exception(\n        pht(\n          'Unable to imagesavealpha() a new empty image: %s',\n          $errors));\n    }\n\n    $trap = new PhutilErrorTrap();\n    $color = @imagecolorallocatealpha($img, 255, 255, 255, 127);\n    $errors = $trap->getErrorsAsString();\n    $trap->destroy();\n    if ($color === false) {\n      throw new Exception(\n        pht(\n          'Unable to imagecolorallocatealpha() a new empty image: %s',\n          $errors));\n    }\n\n    $trap = new PhutilErrorTrap();\n    $ok = @imagefill($img, 0, 0, $color);\n    $errors = $trap->getErrorsAsString();\n    $trap->destroy();\n    if ($ok === false) {\n      throw new Exception(\n        pht(\n          'Unable to imagefill() a new empty image: %s',\n          $errors));\n    }\n\n    return $img;\n  }","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/files/transform/PhabricatorFileImageTransform.php#L180-L216","documentation":"The GD function imagecolorallocatealpha($img, 255, 255, 255, 127) returned false while newEmptyImage() tried to allocate the fully transparent white color used to fill the new canvas. GD returns false only when allocation fails (palette exhausted on palette images, or a broken resource); since the canvas is freshly created truecolor, this points at a broken GD environment rather than the color values themselves.","triggerScenarios":"Reached on every newEmptyImage() call immediately after imagesavealpha(); throws only if imagecolorallocatealpha() reports failure, which stock GD on a valid truecolor image essentially never does.","commonSituations":"Same class as the other GD-step failures in newEmptyImage(): a miscompiled or truncated GD extension, a PHP/GD version mismatch after an upgrade, or resource corruption; not caused by user upload content.","solutions":["Validate and reinstall the GD extension (php -m, reinstall php-gd), restart all PHP processes (php-fpm, Apache, phd daemons).","Pin a known-good PHP/GD combination if it appeared after an upgrade.","Wrap transform execution in try/catch with a fallback to the untransformed file while diagnosing the environment."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  $transformed = $transform->execute($file);\n} catch (Exception $ex) {\n  $transformed = $file;\n}","preventionTips":["Smoke-test the GD install (allocate + fill a tiny truecolor image) as part of deployment checks.","Reinstall php-gd and restart php-fpm/phd after any PHP packaging change.","Log the trapped $errors string from the message — it names the underlying PHP warning."],"tags":["phabricator","image-transform","gd","php","environment"],"backgroundTag":"gd-image-operation-failed","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}