How centering inside line and block with automatically selected font size

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
alexandrly
Posts: 1
Joined: 2019-01-17T01:44:40-07:00
Authentication code: 1152

How centering inside line and block with automatically selected font size

Post by alexandrly » 2019-01-17T02:06:22-07:00

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.

User avatar
fmw42
Posts: 25579
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 » 2019-01-17T15:31:30-07:00

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.

Post Reply