{"record":{"id":"8216f5f1cd6e0c0d","repo":"phacility/phabricator","slug":"unable-to-transform-image-the-imagecreatefromstri","errorCode":null,"errorMessage":"Unable to transform image: the imagecreatefromstring() function is not available. Install or enable the \"gd\" extension for PHP.","messagePattern":"Unable to transform image: the imagecreatefromstring\\(\\) function is not available\\. Install or enable the \"gd\" extension for PHP\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/files/transform/PhabricatorFileImageTransform.php","lineNumber":290,"sourceCode":"\n    $data = $file->loadFileData();\n    $this->data = $data;\n    return $this->data;\n  }\n\n\n  /**\n   * Get the GD image resource for the image being transformed.\n   *\n   * @return resource GD image resource.\n   */\n  protected function getImage() {\n    if ($this->image !== null) {\n      return $this->image;\n    }\n\n    if (!function_exists('imagecreatefromstring')) {\n      throw new Exception(\n        pht(\n          'Unable to transform image: the imagecreatefromstring() function '.\n          'is not available. Install or enable the \"gd\" extension for PHP.'));\n    }\n\n    $data = $this->getData();\n    $data = (string)$data;\n\n    // First, we're going to write the file to disk and use getimagesize()\n    // to determine its dimensions without actually loading the pixel data\n    // into memory. For very large images, we'll bail out.\n\n    // In particular, this defuses a resource exhaustion attack where the\n    // attacker uploads a 40,000 x 40,000 pixel PNGs of solid white. These\n    // kinds of files compress extremely well, but require a huge amount\n    // of memory and CPU to process.\n\n    $tmp = new TempFile();","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/files/transform/PhabricatorFileImageTransform.php#L272-L308","documentation":"getImage() needs imagecreatefromstring() to decode the file, and that function does not exist because the PHP 'gd' extension is not loaded in the process running the transform. Phabricator's GD-based image transforms are therefore entirely unavailable in this environment; the message says exactly which extension to install.","triggerScenarios":"First request for a thumbnail/transform on a host where PHP lacks GD: php -m shows no 'gd'. Note the process that throws may be php-fpm, Apache mod_php, or a phd daemon — whichever one executes the transform worker/request — and each has its own PHP config.","commonSituations":"Fresh server provisioning that never installed php-gd; CLI having GD while php-fpm does not (or vice versa), so tests pass but prod fails; distro PHP upgrade dropping the extension; container images built without the gd package.","solutions":["Install GD: apt-get install php-gd (Debian/Ubuntu) or yum install php-gd (RHEL), matching the PHP version, e.g. php8.2-gd.","Restart every PHP process that can run transforms: php-fpm, Apache, and the Phabricator daemons (phd restart).","Verify per-environment: php -m | grep gd for CLI, and a phpinfo() page / php-fpm check for the web SAPI, plus confirm function_exists('imagecreatefromstring')."],"exampleFix":"# before: extension missing\nphp -m | grep gd   # (no output)\n\n# after\nsudo apt-get install php-gd\nsudo systemctl restart php8.2-fpm apache2\nphp -r 'var_dump(function_exists(\"imagecreatefromstring\"));' // true","handlingStrategy":"validation","validationCode":"if (!function_exists('imagecreatefromstring')) {\n  // GD unavailable: skip transforms, serve originals, and alert ops\n  return $file;\n}","typeGuard":"function gdTransformSupportAvailable(): bool {\n  return extension_loaded('gd') && function_exists('imagecreatefromstring');\n}","tryCatchPattern":null,"preventionTips":["Install php-gd as part of the base host provisioning, not after the first failure.","Verify GD per SAPI: CLI, php-fpm, and phd daemons each load their own PHP config.","Add a deploy-time check: php -r 'exit(function_exists(\"imagecreatefromstring\") ? 0 : 1);'"],"tags":["phabricator","image-transform","gd","php-extension","environment"],"backgroundTag":"missing-php-extension","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}