Skip to content

Commit 06619c6

Browse files
committed
Fix bug when writing ampersand characters
1 parent 7beade9 commit 06619c6

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/FontProcessor.php

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public function boxSize(string $text, FontInterface $font): SizeInterface
4848
*/
4949
public function textToVipsImage(string $text, FontInterface $font, ?ColorInterface $color = null): VipsImage
5050
{
51+
// VipsImage::text() can only handle certain characters as HTML entities
52+
$text = htmlentities($text);
53+
5154
if (!is_null($color)) {
5255
$text = '<span foreground="' . $color->toHex('#') . '">' . $text . '</span>';
5356
}

tests/Unit/Modifiers/TextModifierTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public function testApply(): void
2020
$font->setWrapWidth(300);
2121
$font->setAlignment('center');
2222
$font->setLineHeight(2);
23-
$image->modify(new TextModifier('ABC', new Point(150, 150), $font));
23+
$image->modify(new TextModifier('ABC & D', new Point(150, 150), $font));
2424
}
2525
}

0 commit comments

Comments
 (0)