phacility/phabricator · error · Exception

Unable to imagefill() a new empty image: %s

Error message

Unable to imagefill() a new empty image: %s

What it means

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.

Source

Thrown at src/applications/files/transform/PhabricatorFileImageTransform.php:209

    }

    $trap = new PhutilErrorTrap();
    $color = @imagecolorallocatealpha($img, 255, 255, 255, 127);
    $errors = $trap->getErrorsAsString();
    $trap->destroy();
    if ($color === false) {
      throw new Exception(
        pht(
          'Unable to imagecolorallocatealpha() a new empty image: %s',
          $errors));
    }

    $trap = new PhutilErrorTrap();
    $ok = @imagefill($img, 0, 0, $color);
    $errors = $trap->getErrorsAsString();
    $trap->destroy();
    if ($ok === false) {
      throw new Exception(
        pht(
          'Unable to imagefill() a new empty image: %s',
          $errors));
    }

    return $img;
  }


  /**
   * Get the pixel dimensions of the image being transformed.
   *
   * @return list<int, int> Width and height of the image.
   */
  protected function getImageDimensions() {
    if ($this->imageX === null) {
      $image = $this->getImage();

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. 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).
  2. Keep Phabricator and PHP versions compatible; re-test after upgrades.
  3. Degrade gracefully: catch the exception at the transform boundary and serve the original file.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  $transformed = $transform->execute($file);
} catch (Exception $ex) {
  $transformed = $file;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/7b7c8ff4955fd63b. Report an issue: GitHub.