8
8
use Intervention \Image \Drivers \Imagick \Driver as ImagickDriver ;
9
9
use Intervention \Image \Interfaces \ColorInterface ;
10
10
use Intervention \Image \Interfaces \ImageInterface ;
11
+ use Intervention \Image \Interfaces \SpecializedInterface ;
11
12
use Intervention \Image \Modifiers \TextModifier ;
12
13
use Intervention \Image \Typography \FontFactory ;
13
14
use Intervention \Image \Typography \TextBlock ;
@@ -78,7 +79,7 @@ protected function getPrerenderedBox(): Rectangle
78
79
return $ this ->getFinalTextBox ($ modifier );
79
80
}
80
81
81
- protected function generateModifier (string $ text , Point $ position = new Point ()): CustomTextModifier
82
+ protected function generateModifier (string $ text , Point $ position = new Point ()): SpecializedInterface
82
83
{
83
84
return CustomTextModifier::buildSpecialized (
84
85
new TextModifier (
@@ -131,7 +132,9 @@ protected function getFinalTextBox(CustomTextModifier &$modifier): Rectangle
131
132
$ text = $ this ->text ;
132
133
$ renderedBox = $ this ->getRenderedBoxForText ($ text , $ modifier );
133
134
134
- while (! $ this ->doesTextFitInBox ($ renderedBox )) {
135
+ $ attempts = 0 ;
136
+
137
+ while (! $ this ->doesTextFitInBox ($ renderedBox ) && $ attempts < 10 ) {
135
138
if ($ renderedBox ->width () > $ this ->box ->width ()) {
136
139
$ text = wordwrap ($ text , intval (floor ($ this ->box ->width () / ($ modifier ->boxSize ('M ' )->width () / 1.8 ))));
137
140
$ renderedBox = $ this ->getRenderedBoxForText ($ text , $ modifier );
@@ -150,6 +153,8 @@ protected function getFinalTextBox(CustomTextModifier &$modifier): Rectangle
150
153
}
151
154
152
155
$ modifier = $ this ->generateModifier ($ text , $ modifier ->position );
156
+
157
+ $ attempts ++;
153
158
}
154
159
155
160
return $ renderedBox ;
0 commit comments