phacility/phabricator · error · Exception
Unable to determine image dimensions with imagesx()/imagesy(
Error message
Unable to determine image dimensions with imagesx()/imagesy(): %s
What it means
PhabricatorFileImageTransform::getImageDimensions() could not obtain usable dimensions from the loaded GD resource: imagesx() or imagesy() returned false, or returned a value <= 0. This runs lazily the first time a transform needs the source dimensions, so the failure surfaces as soon as any transform math touches a broken bitmap.
Source
Thrown at src/applications/files/transform/PhabricatorFileImageTransform.php:235
/**
* 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();
$trap = new PhutilErrorTrap();
$x = @imagesx($image);
$y = @imagesy($image);
$errors = $trap->getErrorsAsString();
$trap->destroy();
if (($x === false) || ($y === false) || ($x <= 0) || ($y <= 0)) {
throw new Exception(
pht(
'Unable to determine image dimensions with '.
'imagesx()/imagesy(): %s',
$errors));
}
$this->imageX = $x;
$this->imageY = $y;
}
return array($this->imageX, $this->imageY);
}
/**
* Get the raw file data for the image being transformed.
*
* @return string Raw file data.View on GitHub (pinned to 5720a38cfe)
Solutions
- Verify the file outside Phabricator (php -r 'print_r(getimagesize("file"));' or open it in an image viewer) and re-upload a clean copy.
- In custom subclasses, never assign anything but a GD resource returned by imagecreatefromstring() to the image property.
- Catch the exception at transform time and skip transforms for files that fail, keeping the original.
Defensive patterns
Strategy: try-catch
Validate before calling
$info = @getimagesize($file->getURI());
if ($info === false || $info[0] <= 0 || $info[1] <= 0) {
return null; // not transformable
} Type guard
function hasUsableDimensions($info): bool {
return is_array($info) && $info[0] > 0 && $info[1] > 0;
} Try / catch
try {
list($x, $y) = $transform->getImageDimensions();
} catch (Exception $ex) {
return null; // broken bitmap; skip transform
} Prevention
- Validate uploads with getimagesize() before storing them as images.
- In custom subclasses, only ever assign imagecreatefromstring() results to the image resource.
- Skip transforms for files that fail dimension probing rather than retrying them.
When it happens
Trigger: Transforming a file that earlier passed imagecreatefromstring() but whose resource reports no positive dimensions — corrupted decode, truncated pixel data, or (in custom code) a non-image resource placed into $this->image.
Common situations: Partially corrupted uploads (interrupted transfer) that still decode; files with crafted headers; custom transform subclasses that manipulate or replace the internal image resource with something invalid.
Related errors
- Can not create an image with nonpositive dimensions.
- Failed to imagecopyresampled() image: %s
- Unable to imagecreatetruecolor() a new empty image: %s
- Unable to imagesavealpha() a new empty image: %s
- Unable to imagecolorallocatealpha() a new empty image: %s
AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21).
Data as JSON: /api/errors/b2248112662bac3b.
Report an issue: GitHub.