{"record":{"id":"b2248112662bac3b","repo":"phacility/phabricator","slug":"unable-to-determine-image-dimensions-with-imagesx","errorCode":null,"errorMessage":"Unable to determine image dimensions with imagesx()/imagesy(): %s","messagePattern":"Unable to determine image dimensions with imagesx\\(\\)/imagesy\\(\\): (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/files/transform/PhabricatorFileImageTransform.php","lineNumber":235,"sourceCode":"\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\n      $trap = new PhutilErrorTrap();\n      $x = @imagesx($image);\n      $y = @imagesy($image);\n      $errors = $trap->getErrorsAsString();\n      $trap->destroy();\n\n      if (($x === false) || ($y === false) || ($x <= 0) || ($y <= 0)) {\n        throw new Exception(\n          pht(\n            'Unable to determine image dimensions with '.\n            'imagesx()/imagesy(): %s',\n            $errors));\n      }\n\n      $this->imageX = $x;\n      $this->imageY = $y;\n    }\n\n    return array($this->imageX, $this->imageY);\n  }\n\n\n  /**\n   * Get the raw file data for the image being transformed.\n   *\n   * @return string Raw file data.","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/files/transform/PhabricatorFileImageTransform.php#L217-L253","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"$info = @getimagesize($file->getURI());\nif ($info === false || $info[0] <= 0 || $info[1] <= 0) {\n  return null; // not transformable\n}","typeGuard":"function hasUsableDimensions($info): bool {\n  return is_array($info) && $info[0] > 0 && $info[1] > 0;\n}","tryCatchPattern":"try {\n  list($x, $y) = $transform->getImageDimensions();\n} catch (Exception $ex) {\n  return null; // broken bitmap; skip transform\n}","preventionTips":["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."],"tags":["phabricator","image-transform","gd","dimensions","php"],"backgroundTag":"gd-image-operation-failed","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}