A
A
Ainur Shakirov2017-07-03 20:54:52
ImageMagick
Ainur Shakirov, 2017-07-03 20:54:52

How to calculate text length in Imagick(fluid, responsive)?

I put text:

$draw = new ImagickDraw();
    $bg = new Imagick($fileName);
    $draw->setTextAlignment(Imagick::ALIGN_CENTER);
    $draw->setFont($fontName);
    $draw->setFontSize($fontSize);
    $draw->setFillColor($fontColor);
    $bg->annotateImage($draw, $x, $y, $angle, $text);
    $bg->setImageFormat("png");
    $bg->writeImage($outfileName)

How to calculate the font size so that it fits in Npx?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmaw, 2020-03-06
@Fqyeh29

https://www.php.net/manual/en/imagick.queryfontmet...

$size = $bg->queryFontMetrics($draw, 'Ширина текста');
echo '<pre>';	var_dump($size);	echo '</pre>';	
$w = $size['textWidth'];
$h = $size['textHeight'];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question