{"record":{"id":"df3326efec5175b9","repo":"phacility/phabricator","slug":"unable-to-imagesavealpha-a-new-empty-image-s","errorCode":null,"errorMessage":"Unable to imagesavealpha() a new empty image: %s","messagePattern":"Unable to imagesavealpha\\(\\) a new empty image: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/files/transform/PhabricatorFileImageTransform.php","lineNumber":187,"sourceCode":"    }\n\n    $trap = new PhutilErrorTrap();\n    $img = @imagecreatetruecolor($w, $h);\n    $errors = $trap->getErrorsAsString();\n    $trap->destroy();\n    if ($img === false) {\n      throw new Exception(\n        pht(\n          'Unable to imagecreatetruecolor() a new empty image: %s',\n          $errors));\n    }\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);","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/files/transform/PhabricatorFileImageTransform.php#L169-L205","documentation":"The GD function imagesavealpha($img, true) returned false while newEmptyImage() was configuring the freshly created truecolor canvas to preserve its alpha channel. This step normally cannot fail for a valid truecolor resource, so a false return indicates a broken GD build, a corrupted image resource from an earlier step, or memory corruption-level problems rather than caller input.","triggerScenarios":"Any call to PhabricatorFileImageTransform::newEmptyImage() where imagecreatetruecolor() succeeded but the subsequent imagesavealpha() call fails — typically observed with mismatched/buggy GD versions or after the image resource was invalidated.","commonSituations":"Exotic or miscompiled GD builds (e.g. partial PHP packages where GD is present but incomplete); upgrading PHP/GD and hitting a regression; extremely rare in stock distro PHP where this call succeeds unconditionally on truecolor images.","solutions":["Verify the GD install: php -i | grep -i gd, and confirm bundled GD with PNG support.","Reinstall/upgrade the php-gd package (apt install --reinstall php-gd or the distro equivalent) and restart php-fpm/web server plus daemons.","If it persists, capture $errors from the message and file it upstream; guard call sites with try/catch to degrade to the original image."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  $transformed = $transform->execute($file);\n} catch (Exception $ex) {\n  phlog($ex);\n  $transformed = $file; // GD environment issue; serve original\n}","preventionTips":["Validate GD health after PHP upgrades with a minimal imagecreatetruecolor+imagesavealpha script.","Keep PHP and php-gd versions matched; reinstall php-gd when in doubt.","Never let a transform failure break the request — always fall back to the original."],"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"}