Same name and namespace in other branches
  1. 8.x-1.x tests/exif_orientation.test \ExifOrientationTest::assertImageIsRotated() 1 comment

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

Class

ExifOrientationTest
@file Tests for <a href="/en/work/drupal-api/exif_orientation/exif_orientation.module/7.x-1.x" title="Module file for EXIF Orientation" class="local">exif_orientation.module</a>.

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.');
}