@@ -539,13 +539,7 @@ public function opacity(int $opacity = 100) : static
539539 */
540540 public function rotate (float $ angle ) : static
541541 {
542- if ($ this ->hasAlpha ()) {
543- \imagealphablending ($ this ->instance , false );
544- \imagesavealpha ($ this ->instance , true );
545- $ background = \imagecolorallocatealpha ($ this ->instance , 0 , 0 , 0 , 127 );
546- } else {
547- $ background = \imagecolorallocate ($ this ->instance , 255 , 255 , 255 );
548- }
542+ $ background = $ this ->allocateBackground ();
549543 if ($ background === false ) {
550544 throw new RuntimeException ('Image could not allocate a color ' );
551545 }
@@ -557,6 +551,16 @@ public function rotate(float $angle) : static
557551 return $ this ;
558552 }
559553
554+ protected function allocateBackground () : false | int
555+ {
556+ if ($ this ->hasAlpha ()) {
557+ \imagealphablending ($ this ->instance , false );
558+ \imagesavealpha ($ this ->instance , true );
559+ return \imagecolorallocatealpha ($ this ->instance , 0 , 0 , 0 , 127 );
560+ }
561+ return \imagecolorallocate ($ this ->instance , 255 , 255 , 255 );
562+ }
563+
560564 public function hasAlpha () : bool
561565 {
562566 return \in_array (
0 commit comments