You are here

public function RectangleTest::providerPhp55RotateDimensions in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Utility/RectangleTest.php \Drupal\Tests\Component\Utility\RectangleTest::providerPhp55RotateDimensions()

Provides data for image dimension rotation tests.

This dataset sample was generated by running on PHP 5.5 the function below

  • first, for all integer rotation angles (-360 to 360) on a rectangle 40x20;
  • second, for 500 random float rotation angle in the range -360 to 360 on a rectangle 40x20;
  • third, on 1000 rectangles of random WxH rotated to a random float angle in the range -360 to 360
  • fourth, on 2000 rectangles of random WxH rotated to a random integer angle multiple of 30 degrees in the range -360 to 360 (which is the most tricky case).

Using the GD toolkit operations gives us true data coming from the GD library that can be used to match against the Rectangle class under test.


  protected function rotateResults($width, $height, $angle, &$new_width, &$new_height) {
    $image = \Drupal::service('image.factory')->get(NULL, 'gd');
    $image->createNew($width, $height);
    $old_res = $image->getToolkit()->getResource();
    $image->rotate($angle);
    $new_width = $image->getWidth();
    $new_height = $image->getHeight();
    if (is_resource($old_res)) {
      imagedestroy($old_res);
    }
  }

Return value

array[] A simple array of simple arrays, each having the following elements:

  • original image width
  • original image height
  • rotation angle in degrees
  • expected image width after rotation
  • expected image height after rotation

See also

testRotateDimensions()

File

core/tests/Drupal/Tests/Component/Utility/RectangleTest.php, line 100

Class

RectangleTest
@coversDefaultClass \Drupal\Component\Utility\Rectangle @group Image

Namespace

Drupal\Tests\Component\Utility

Code

public function providerPhp55RotateDimensions() {

  // The dataset is stored in a .json file because it is very large and causes
  // problems for PHPCS.
  return json_decode(file_get_contents(__DIR__ . '/fixtures/RectangleTest.json'));
}