image
image copied to clipboard
Wrong text position
I'm building an application base on the Intervention image - imagick, this library working well so far. But I have a problem with render text with custom fonts. It seems like it is wrong line-height
(I know intervention doesn't have line-height at all). Here is the result
- The top left item was rendered by Monsreat (regular) fonts.
- The other text was used Parisienne (regular) fonts.
I deeply research to source code of Intervention (Imagick) and found that line
Can someone explain why we have to put: 0.65 / 2
to the center - line 67?
$posy = $posy + $dimensions['textHeight'] * 0.65 / 2;
And do you have any idea how can I correct the position for my text? Thanks.
Hi @mihnsen,
I was about the raise an issue asking the same question. In my case, I was planning to create an image and inserting it into the main image. I believe it might fix the issue.
Something like this:
$imagickImage = new \Imagick();
$draw = new \ImagickDraw();
$draw->setGravity(\Imagick::GRAVITY_NORTH);
$draw->setFont($fontSource);
$draw->setFontSize($fontSize);
$draw->setFillColor( 'black');
$info = $imagickImage->queryFontMetrics($draw, 'text');
$imagickImage->newImage((int) $info['textWidth'], (int) $info['textHeight'], 'none');
$imagickImage->annotateImage($draw, 0, 0, 0, 'text');
$imagickImage->setImageFormat('png');
$interventionImage->insert($imagickImage, ...);
I suggest to try this task with Intervention Image 3 which supports line height.