Page 1 of 1

How centering inside line and block with automatically selected font size

Posted: 2019-01-17T02:06:22-07:00
by alexandrly
All welcome, I apply a solution based on https://gist.github.com/clifgriffin/728 ... 7b81fa2d8a where a text block is set and the size of the text is automatically selected depending on the length of the text, download https://yadi.sk/d/KExniPdnz1N1cw .
1)It is necessary now that the text is centered inside the specified box and line, clearly here https://yadi.sk/i/iSkVEDfrOLs_uA
2) Also i want to rotate text correctly
Really looking forward to help on this solution for PHP 5.4.

Re: How centering inside line and block with automatically selected font size

Posted: 2019-01-17T15:31:30-07:00
by fmw42
Sorry, I do not code Imagick. Best I can tell you is that in this line:

$NewImage->annotateImage( $draw, $x_pos, $y_pos + ($i * $line_height * $line_height_ratio), 0, $lines[$i] );

You need to compute the $x_pos, so that the text will be centered. Measure the text width and the image width and offset by half the difference.