{"record":{"id":"7b7c8ff4955fd63b","repo":"phacility/phabricator","slug":"unable-to-imagefill-a-new-empty-image-s","errorCode":null,"errorMessage":"Unable to imagefill() a new empty image: %s","messagePattern":"Unable to imagefill\\(\\) a new empty image: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/files/transform/PhabricatorFileImageTransform.php","lineNumber":209,"sourceCode":"    }\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  }\n\n\n  /**\n   * Get the pixel dimensions of the image being transformed.\n   *\n   * @return list<int, int> Width and height of the image.\n   */\n  protected function getImageDimensions() {\n    if ($this->imageX === null) {\n      $image = $this->getImage();\n","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/files/transform/PhabricatorFileImageTransform.php#L191-L227","documentation":"The GD function imagefill($img, 0, 0, $color) returned false as the last step of newEmptyImage(), meaning the transparent color could not be flooded over the new canvas. With a valid truecolor image and a successfully allocated color this call does not fail in stock GD, so like the preceding steps this signals a damaged GD environment or invalid resource rather than bad dimensions or bad input data.","triggerScenarios":"Every newEmptyImage() call performs this fill; the exception fires only when imagefill() explicitly reports failure after the resource, alpha flag, and color were all created.","commonSituations":"Broken or partial GD installs; resource lifetime bugs in custom code that stores GD resources across requests (e.g. under mod_php with accidental caching); observed almost never on standard distro PHP+GD.","solutions":["Sanity-check GD with a minimal script (imagecreatetruecolor + imagecolorallocatealpha + imagefill) outside Phabricator; if that fails, fix the PHP/GD environment (reinstall php-gd, restart php-fpm/phd).","Keep Phabricator and PHP versions compatible; re-test after upgrades.","Degrade gracefully: catch the exception at the transform boundary and serve the original file."],"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":["Run a GD sanity check in CI/deploy (create, savealpha, allocate, fill) so environment breakage is caught before users.","Do not cache GD resources across requests in custom code.","Keep a graceful 'original file' fallback for every transform call site."],"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"}