Same name in other branches
- 8.x-1.x 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 dans tests/
exif_orientation.test - Test auto rotation of uploaded user profile pictures.
Fichier
-
tests/
exif_orientation.test, line 90
Classe
- 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.');
}