@@ -105,13 +105,18 @@ protected function createTransparentDataURI(string $hexColor, int $width = 1, in
105105 throw new \RuntimeException ('Color is not a valid hexadecimal RGB format ' );
106106 }
107107 [$ r , $ g , $ b ] = $ hexColorArray ;
108+ $ width = max (1 , $ width );
109+ $ height = max (1 , $ height );
110+ $ red = max (0 , min (255 , $ r ?? 0 ));
111+ $ green = max (0 , min (255 , $ g ?? 0 ));
112+ $ blue = max (0 , min (255 , $ b ?? 0 ));
108113 $ im = \imagecreatetruecolor ($ width , $ height );
109114 if ($ im ) {
110115 \imagefill (
111116 $ im ,
112117 0 ,
113118 0 ,
114- \imagecolorallocate ($ im , $ r ?? 0 , $ g ?? 0 , $ b ?? 0 ) ?: 0
119+ \imagecolorallocate ($ im , $ red , $ green , $ blue ) ?: 0
115120 );
116121 \ob_start ();
117122 \imagejpeg ($ im , null , 30 );
@@ -126,9 +131,9 @@ protected function createTransparentDataURI(string $hexColor, int $width = 1, in
126131
127132 protected function getImageRatio (array &$ options ): ?float
128133 {
129- /** @var \ArrayAccess <string, string|null> $options */
134+ /** @var array <string, string|int|float |null> $options */
130135 $ compositing = $ options ['crop ' ] ?? $ options ['fit ' ] ?? '' ;
131- if (1 === preg_match (static ::WIDTH_HEIGHT_PATTERN , $ compositing , $ matches )) {
136+ if (1 === preg_match (static ::WIDTH_HEIGHT_PATTERN , ( string ) $ compositing , $ matches )) {
132137 return ((float ) $ matches ['width ' ]) / ((float ) $ matches ['height ' ]);
133138 }
134139
@@ -137,9 +142,9 @@ protected function getImageRatio(array &$options): ?float
137142
138143 protected function getImageWidth (array &$ options ): int
139144 {
140- /** @var \ArrayAccess <string, string|null> $options */
145+ /** @var array <string, string|int|float |null> $options */
141146 $ compositing = $ options ['fit ' ] ?? '' ;
142- if (1 === preg_match (static ::WIDTH_HEIGHT_PATTERN , $ compositing , $ matches )) {
147+ if (1 === preg_match (static ::WIDTH_HEIGHT_PATTERN , ( string ) $ compositing , $ matches )) {
143148 return (int ) $ matches ['width ' ];
144149 } elseif (null !== $ options ['ratio ' ] && 0 !== $ options ['height ' ] && 0 !== $ options ['ratio ' ]) {
145150 return (int ) (intval ($ options ['height ' ]) * floatval ($ options ['ratio ' ]));
@@ -150,9 +155,9 @@ protected function getImageWidth(array &$options): int
150155
151156 protected function getImageHeight (array &$ options ): int
152157 {
153- /** @var \ArrayAccess <string, string|null> $options */
158+ /** @var array <string, string|int|float |null> $options */
154159 $ compositing = $ options ['fit ' ] ?? '' ;
155- if (1 === preg_match (static ::WIDTH_HEIGHT_PATTERN , $ compositing , $ matches )) {
160+ if (1 === preg_match (static ::WIDTH_HEIGHT_PATTERN , ( string ) $ compositing , $ matches )) {
156161 return (int ) $ matches ['height ' ];
157162 } elseif (null !== $ options ['ratio ' ] && 0 !== $ options ['width ' ] && 0 !== $ options ['ratio ' ]) {
158163 return (int ) (intval ($ options ['width ' ]) / floatval ($ options ['ratio ' ]));
@@ -176,7 +181,7 @@ protected function additionalAssignation(BaseDocumentInterface $document, array
176181 $ assignation ['height ' ] = $ options ['height ' ] = $ this ->getImageHeight ($ options );
177182 }
178183
179- if (!( $ document instanceof AdvancedDocumentInterface) ) {
184+ if (!$ document instanceof AdvancedDocumentInterface) {
180185 return ;
181186 }
182187
0 commit comments