Unverified Commit 749dd1d0 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3233015 by alexpott, longwave: Refactor...

Issue #3233015 by alexpott, longwave: Refactor \Drupal\Component\Utility\Random::image() to not trigger deprecations in PHP 8.1
parent 1b66ab0c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -287,13 +287,13 @@ public function image($destination, $min_resolution, $max_resolution) {
      $color = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
      $x = $width / 2 * ($n % 2);
      $y = $height / 2 * (int) ($n >= 2);
      imagefilledrectangle($im, $x, $y, $x + $width / 2, $y + $height / 2, $color);
      imagefilledrectangle($im, (int) $x, (int) $y, (int) ($x + $width / 2), (int) ($y + $height / 2), $color);
    }

    // Make a perfect circle in the image middle.
    $color = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
    $smaller_dimension = min($width, $height);
    imageellipse($im, $width / 2, $height / 2, $smaller_dimension, $smaller_dimension, $color);
    imageellipse($im, (int) ($width / 2), (int) ($height / 2), $smaller_dimension, $smaller_dimension, $color);

    $save_function = 'image' . ($extension == 'jpg' ? 'jpeg' : $extension);
    $save_function($im, $destination);