You are here

private function ExifOrientationTest::assertImageIsRotated in EXIF Orientation 8

Same name and namespace in other branches
  1. 7 tests/exif_orientation.test \ExifOrientationTest::assertImageIsRotated()

Verify that an image is landscape and has a red top left corner.

1 call to ExifOrientationTest::assertImageIsRotated()
ExifOrientationTest::testUserPicture in tests/exif_orientation.test
Test auto rotation of uploaded user profile pictures.

File

tests/exif_orientation.test, line 90
Tests for exif_orientation.module.

Class

ExifOrientationTest
@file Tests for exif_orientation.module.

Code

private function assertImageIsRotated($uri) {
  $uri = drupal_realpath($uri);
  $img = image_load($uri);
  $this
    ->assertTrue(is_object($img), 'Image data is available.');

  // Test the aspect ratio.
  $this
    ->assertTrue($img->info['width'] > $img->info['height'], 'The image format is landscape.');

  // Verify the rotation by color inspection.
  $rgb = imagecolorat($img->resource, 10, 10);
  $r = $rgb >> 16 & 0xff;
  $g = $rgb >> 8 & 0xff;
  $b = $rgb & 0xff;

  // The top left corner should be red.
  $this
    ->assertTrue(abs($r - 255) < 5, 'Red color component is close to 255.');
  $this
    ->assertTrue($g < 5, 'Green color component is close to 0.');
  $this
    ->assertTrue($b < 5, 'Blue color component is close to 0.');
}