@@ -216,37 +216,42 @@ public function setBackgroundColor(array $rgbArray)
216216 */
217217 public function setSize ($ size )
218218 {
219+ if (is_numeric ($ size )) {
220+ $ this ->setWidth ((int ) $ size )->setHeight ((int ) $ size );
221+ return $ this ;
222+ }
223+
219224 $ width = null ;
220225 $ height = null ;
221226
222- $ hasWidthDimensions = false ;
223- $ hasHeightDimensions = false ;
227+ $ endsWithSeparator = false ;
228+ $ startsWithSeparator = false ;
224229
225230 $ hasDimensions = str_contains ($ size , self ::DIMENSIONS_SEPARATOR );
226231
227232 if ($ hasDimensions ) {
228- $ hasWidthDimensions = str_ends_with ($ size , self ::DIMENSIONS_SEPARATOR );
229- $ hasHeightDimensions = str_starts_with ($ size , self ::DIMENSIONS_SEPARATOR );
233+ $ endsWithSeparator = str_ends_with ($ size , self ::DIMENSIONS_SEPARATOR );
234+ $ startsWithSeparator = str_starts_with ($ size , self ::DIMENSIONS_SEPARATOR );
230235 }
231236
232- if ($ hasHeightDimensions && !$ hasWidthDimensions ) {
237+ if ($ startsWithSeparator && !$ endsWithSeparator ) {
233238 $ dimension = substr ($ size , 1 );
234239 $ height = $ dimension ? (int ) $ dimension : null ;
235240 }
236241
237- if ($ hasWidthDimensions && !$ hasHeightDimensions ) {
242+ if ($ endsWithSeparator && !$ startsWithSeparator ) {
238243 $ dimension = substr ($ size , 0 , -1 );
239244 $ width = $ dimension ? (int ) $ dimension : null ;
240245 }
241246
242247 // determine width and height from string
243- if ($ hasDimensions && (!$ hasWidthDimensions && !$ hasHeightDimensions )) {
244- [$ width , $ height ] = array_map (intval (...), explode ( self :: DIMENSIONS_SEPARATOR , strtolower ( $ size ), 2 ));
245- }
246-
247- if ( is_numeric ( $ size )) {
248- $ width = ( int ) $ size;
249- $ height = ( int ) $ size ;
248+ if ($ hasDimensions && (!$ endsWithSeparator && !$ startsWithSeparator )) {
249+ [$ width , $ height ] = array_map (
250+ static function ( $ value ) {
251+ return $ value === '' ? null : ( int ) $ value ;
252+ },
253+ explode ( self :: DIMENSIONS_SEPARATOR , strtolower ( $ size), 2 )
254+ ) ;
250255 }
251256
252257 // set sizes
0 commit comments