{"record":{"id":"4ebe8a73cd6b2ea1","repo":"Intervention/image","slug":"failed-to-apply-self-class-unable-to-dra","errorCode":null,"errorMessage":"Failed to apply ' . self::class . ', unable to draw text line","messagePattern":"Failed to apply ' \\. self::class \\. ', unable to draw text line","errorType":"exception","errorClass":"ModifierException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Modifiers/TextModifier.php","lineNumber":128,"sourceCode":"     * @throws ModifierException\n     */\n    private function maybeDrawTextline(\n        FrameInterface $frame,\n        Line $textline,\n        ?ImagickDraw $draw = null,\n        PointInterface $offset = new Point(),\n    ): void {\n        if ($draw instanceof ImagickDraw) {\n            try {\n                $result = $frame->native()->annotateImage(\n                    $draw,\n                    $textline->position()->x() + $offset->x(),\n                    $textline->position()->y() + $offset->y(),\n                    $this->font->angle(),\n                    (string) $textline,\n                );\n            } catch (ImageException $e) {\n                throw new ModifierException(\n                    'Failed to apply ' . self::class . ', unable to draw text line',\n                    previous: $e,\n                );\n            }\n\n            if ($result === false) {\n                throw new ModifierException(\n                    'Failed to apply ' . self::class . ', unable to draw text line',\n                );\n            }\n        }\n    }\n\n    /**\n     * Return imagick font processor\n     *\n     * @throws DriverException\n     * @throws StateException","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Modifiers/TextModifier.php#L110-L146","documentation":"ModifierException from the Imagick text modifier: annotateImage() threw an ImageException while drawing a single line of text. The most common root cause is an unusable font - ImagickDraw silently accepts a bad font file and the failure only surfaces when annotation runs. The original exception is attached via getPrevious().","triggerScenarios":"$image->text('hello', $x, $y, fn ($font) => $font->filename($fontPath)) where the font file does not exist, is unreadable (permissions, open_basedir), or is not a loadable TTF/OTF for ImageMagick's FreeType delegate; each text line is drawn individually so the throw happens per line.","commonSituations":"Relative font paths that resolve differently between CLI and web SAPI; font files outside the PHP open_basedir; corrupt or non-TrueType font files; servers missing the FreeType delegate in ImageMagick.","solutions":["Verify the font path exists and is readable (is_file() + is_readable()) before calling text()","Use an absolute path to the font file","Test the font with ImageMagick directly or a raw Imagick script to confirm FreeType can load it","Catch ModifierException and inspect getPrevious() for the underlying reason"],"exampleFix":"// before\n$image->text('hello', 10, 50, fn ($font) => $font->filename('fonts/arial.ttf'));\n\n// after\n$fontPath = '/var/www/app/fonts/arial.ttf';\nif (!is_readable($fontPath)) {\n    throw new RuntimeException(\"Font not readable: {$fontPath}\");\n}\n$image->text('hello', 10, 50, fn ($font) => $font->filename($fontPath));","handlingStrategy":"validation","validationCode":"if (!is_string($fontPath) || !is_file($fontPath) || !is_readable($fontPath)) {\n    throw new InvalidArgumentException(\"Font file missing or unreadable: {$fontPath}\");\n}\n$image->text('hello', $x, $y, fn ($font) => $font->filename($fontPath));","typeGuard":"function isUsableFontFile(string $path): bool\n{\n    return is_file($path) && is_readable($path) && str_ends_with(strtolower($path), '.ttf');\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\ModifierException;\n\ntry {\n    $image->text($line, $x, $y, $fontCallback);\n} catch (ModifierException $e) {\n    $reason = $e->getPrevious()?->getMessage() ?? $e->getMessage();\n    throw new RuntimeException(\"Text draw failed for font {$fontPath}: {$reason}\", 0, $e);\n}","preventionTips":["Store fonts with the application and reference them by absolute path","Check is_readable() once at bootstrap for every configured font, not per request","Watch open_basedir restrictions when fonts live outside the web root"],"tags":["imagick","text","font","annotation","freetype"],"backgroundTag":"imagick-operation-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}