I have a function that successfully inserts text into an image, based on the font size, font color, text coordinates, the text string itself, and the background image. The function is working perfectly. However, I have an option to concatenate the username with some sample text, so that the string can be generated in the image. This happens in two different ways:
1.Username + Text -> this is the text to be generated in the image.
2.Text + Username -> this is the text to be generated in the image.
This is code sample for the options:
$textValue = $username . ' ' . $textValue;
$textValue = $textValue . ' ' . $username;
Next time please put the code in the comment image in the question. It is also much easier to mark code out and for me to copy anything.
In the code you show (https://i.imgsafe.org/ab071c1bf7.png) you call
->textBox() with both heigth, width and fontSize specified.
If you leave out the height, the code will just wrap the string for you over multiple lines, so that is one solution.
At the moment the fontSize is reduced in size by the
->fitToWidth() function until it should fit. Either the problem is that this function works incorrectly because it does not work well with Unicode characters or because the font itself cannot be drawn at the size calculated and this is written larger.