{"record":{"id":"626fac71e285da8d","repo":"Intervention/image","slug":"no-font-file-specified","errorCode":null,"errorMessage":"No font file specified","messagePattern":"No font file specified","errorType":"exception","errorClass":"StateException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/FontProcessor.php","lineNumber":62,"sourceCode":"\n        return new Size(\n            intval(round($dimensions['textWidth'])),\n            intval(round($dimensions['ascender'] + $dimensions['descender'])),\n        );\n    }\n\n    /**\n     * Imagick::annotateImage() needs an ImagickDraw object - this method takes\n     * the font object as the base and adds an optional passed color to the new\n     * ImagickDraw object.\n     *\n     * @throws StateException\n     * @throws DriverException\n     */\n    public function toImagickDraw(FontInterface $font, ?ImagickPixel $color = null): ImagickDraw\n    {\n        if (!$font->hasFile()) {\n            throw new StateException('No font file specified');\n        }\n\n        try {\n            $draw = new ImagickDraw();\n            $draw->setStrokeAntialias(true);\n            $draw->setTextAntialias(true);\n            $draw->setFont($font->filepath());\n            $draw->setFontSize($this->nativeFontSize($font));\n            $draw->setTextAlignment(Imagick::ALIGN_LEFT);\n\n            if ($color instanceof ImagickPixel) {\n                $draw->setFillColor($color);\n            }\n        } catch (ImagickException | ImagickDrawException $e) {\n            throw new DriverException('Failed to convert font to ImagickDraw instance', previous: $e);\n        }\n\n        return $draw;","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/FontProcessor.php#L44-L80","documentation":"toImagickDraw() throws StateException 'No font file specified' when the Font object has no file attached (src/Drivers/Imagick/FontProcessor.php:61-63). The Imagick driver has no built-in fallback font, so every text() or boxSize() call must supply a font file via the font closure. This is a pure usage error thrown before any ImageMagick call — nothing environmental.","triggerScenarios":"Calling $image->text('Hello', $x, $y, fn ($font) => $font->size(24)->color('f00')) without ->file(...); building an Intervention\\Image\\Typography\\Font manually and never calling setFilepath() before boxSize()/toImagickDraw().","commonSituations":"Copy-pasting GD examples or Intervention Image v2 snippets where a default font existed; assuming a system default font is used; the font file argument simply forgotten during refactoring.","solutions":["Add ->file($path) inside the font closure of your text() call","Use an absolute path to a font you ship with the app (e.g. base_path('fonts/Inter-Regular.ttf'))","Verify at runtime: is_readable($path) before calling text()","Do not rely on system font paths that differ between dev, CI, and production"],"exampleFix":"// before\n$image->text('Hello', 100, 100, function ($font) {\n    $font->size(24);\n});\n\n// after\n$image->text('Hello', 100, 100, function ($font) {\n    $font->file(base_path('fonts/Inter-Regular.ttf'));\n    $font->size(24);\n});","handlingStrategy":"validation","validationCode":"$fontFile = realpath(__DIR__ . '/fonts/Inter-Regular.ttf');\nif ($fontFile === false || !is_readable($fontFile)) {\n    throw new RuntimeException('Font file missing: ' . $fontFile);\n}\n// ->file() is what prevents the StateException\n$image->text('Hello', 100, 100, fn ($font) => $font->file($fontFile));","typeGuard":"// If you build Font objects yourself\nif (!method_exists($font, 'hasFile') || !$font->hasFile()) {\n    throw new RuntimeException('Font has no file; Imagick driver requires one');\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\StateException;\n\ntry {\n    $image->text($label, $x, $y, fn ($font) => $font->file($this->fontPath)->size(20));\n} catch (StateException $e) {\n    // usage bug: font file not set — fix the closure, do not retry\n    throw new LogicException('text() requires ->file() on the Imagick driver', 0, $e);\n}","preventionTips":["Always set ->file() in the font closure; treat it as required on the Imagick driver","Keep fonts inside the repo and reference absolute paths","Assert in tests that your text helper includes a font file"],"tags":["imagick","font","text","state","usage-error"],"backgroundTag":"missing-font-file","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}