image
image copied to clipboard
getBoxSize() from \Intervention\Image\Gd\Font modifies UTF-8 Text Input
The getBoxSize() function of \Intervention\Image\Gd\Font has the following behaviour which seems to be unwanted.
Problem:
$text = 'Jörg';
$font = new \Intervention\Image\Gd\Font($text);
$font->file(public_path('fonts/montserrat-v14-latin-700.ttf'));
$font->valign('top');
$box = $font->getBoxSize();
dump($font->getText()); // internal text is: Jörg
// getBoxSize() is called in applyToImage()
// Jörg is written on the image
$font->applyToImage($this->stage, 200, 200);
dump($font->getText()); // internal text is: Jörg
Inside getBoxSize()
$this->text = mb_encode_numericentity($this->text, array(0x0080, 0xffff, 0, 0xffff), 'UTF-8');
is called, which modifies Codepoints above 0x0080 to decimal unicode representation.
My suggestion would be either to document this behaviour or to restore the original text input.
Just found out doing this:
$text = "哈哈哈";
$font = new \Intervention\Image\Gd\Font($text);
// ...
$box = $font->getBoxSize();
$font->text($text); <--- tihs reset
// ...
solves my problem.
This issue should be resolved as of version 3.