{"record":{"id":"a3698b54033bd70b","repo":"Intervention/image","slug":"unable-to-calculate-box-size-of-font","errorCode":null,"errorMessage":"Unable to calculate box size of font","messagePattern":"Unable to calculate box size of font","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/FontProcessor.php","lineNumber":56,"sourceCode":"                    $chars * $this->gdCharacterWidth($gdFont),\n                );\n                $box->setHeight(\n                    $this->gdCharacterHeight($gdFont),\n                );\n            }\n            return $box;\n        }\n\n        // calculate box size from ttf font file with angle 0\n        $box = imageftbbox(\n            size: $this->nativeFontSize($font),\n            angle: 0,\n            font_filename: $font->filepath(),\n            string: $text,\n        );\n\n        if ($box === false) {\n            throw new DriverException('Unable to calculate box size of font');\n        }\n\n        // build size from points\n        return new Size(\n            width: intval(abs($box[6] - $box[4])), // difference of upper-left-x and upper-right-x\n            height: intval(abs($box[7] - $box[1])), // difference if upper-left-y and lower-left-y\n            pivot: new Point($box[6], $box[7]), // position of upper-left corner\n        );\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see FontProcessorInterface::nativeFontSize()\n     */\n    public function nativeFontSize(FontInterface $font): float\n    {\n        return floatval(round($font->size() * .76, 6));","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/FontProcessor.php#L38-L74","documentation":"The GD FontProcessor measures text by calling imageftbbox(); it returns false when FreeType cannot work with the given font file or text. The usual cause is a missing, unreadable, or invalid font path rather than anything about the image being annotated.","triggerScenarios":"$image->text('Hi', 100, 100, 'fonts/missing.ttf') where the path is wrong or unreadable; a font format FreeType cannot parse (e.g. WOFF); relative paths resolving differently between CLI and web SAPIs.","commonSituations":"Font path typos, font assets not copied into Docker builds, file permissions on shared hosting, passing .woff files that must be converted to TTF first.","solutions":["Verify with file_exists() and is_readable() before rendering","Use absolute paths built from __DIR__ or a configured asset root","Confirm the file is TTF/OTF, not WOFF/WOFF2; convert if needed","Sanity-test the font with imageftbbox(12, 0, $font, 'Test') directly","Use the Imagick driver's text rendering as a fallback for exotic fonts"],"exampleFix":"// before\n$image->text('Hello', 100, 100, 'app/fonts/missing.ttf');\n\n// after\n$fontFile = realpath(__DIR__ . '/../fonts/inter.ttf');\nif ($fontFile === false || !is_readable($fontFile)) {\n    throw new RuntimeException('Font file missing or unreadable');\n}\n$image->text('Hello', 100, 100, $fontFile);","handlingStrategy":"validation","validationCode":"if (!is_string($fontFile) || !is_readable($fontFile)) {\n    throw new RuntimeException('Font file not readable: ' . $fontFile);\n}\n$image->text('Hello', 100, 100, $fontFile);","typeGuard":"function isReadableFont(mixed $font): bool\n{\n    return is_string($font) && is_readable($font);\n}","tryCatchPattern":"try {\n    $image->text('Hello', 100, 100, $fontFile);\n} catch (DriverException $e) {\n    // font unreadable/invalid: fall back to a bundled default font\n}","preventionTips":["Use absolute font paths built from a known root","Verify font assets exist in Docker builds (COPY them explicitly)","Accept only TTF/OTF files; convert WOFF upstream"],"tags":["font","ttf","freetype","text-rendering","gd"],"backgroundTag":"font-load-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}