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
- 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.
Defensive patterns
Strategy: try-catch
Try / catch
try {
$transformed = $transform->execute($file);
} catch (Exception $ex) {
$transformed = $file;
} Prevention
- 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.
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
- Unable to imagesavealpha() a new empty image: %s
- Unable to imagecolorallocatealpha() a new empty image: %s
- Failed to imagecopyresampled() image: %s
- Can not create an image with nonpositive dimensions.
- Unable to imagecreatetruecolor() a new empty image: %s
AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21).
Data as JSON: /api/errors/7b7c8ff4955fd63b.
Report an issue: GitHub.