Ticket #37140: 37140-1.patch
| File 37140-1.patch, 4.2 KB (added by , 10 years ago) |
|---|
-
src/wp-includes/class-wp-image-editor-imagick.php
diff --git src/wp-includes/class-wp-image-editor-imagick.php src/wp-includes/class-wp-image-editor-imagick.php index 82b872d..f9680de 100644
class WP_Image_Editor_Imagick extends WP_Image_Editor { 538 538 try { 539 539 $this->image->rotateImage( new ImagickPixel('none'), 360-$angle ); 540 540 541 /** 542 * Normalise rotation exif data so it's consistent across devices with 543 * what the user is seeing on the current device. 544 */ 545 $this->image->setImageOrientation( Imagick::ORIENTATION_TOPLEFT ); 546 541 547 // Since this changes the dimensions of the image, update the size. 542 548 $result = $this->update_size(); 543 549 if ( is_wp_error( $result ) ) -
new file tests/phpunit/tests/image/orientation.php
diff --git tests/phpunit/data/images/orientation-1.jpg tests/phpunit/data/images/orientation-1.jpg new file mode 100644 index 0000000..015c5f1 Binary files /dev/null and tests/phpunit/data/images/orientation-1.jpg differ diff --git tests/phpunit/data/images/orientation-2.jpg tests/phpunit/data/images/orientation-2.jpg new file mode 100644 index 0000000..2e7fb57 Binary files /dev/null and tests/phpunit/data/images/orientation-2.jpg differ diff --git tests/phpunit/data/images/orientation-3.jpg tests/phpunit/data/images/orientation-3.jpg new file mode 100644 index 0000000..74505cf Binary files /dev/null and tests/phpunit/data/images/orientation-3.jpg differ diff --git tests/phpunit/data/images/orientation-4.jpg tests/phpunit/data/images/orientation-4.jpg new file mode 100644 index 0000000..ea133fb Binary files /dev/null and tests/phpunit/data/images/orientation-4.jpg differ diff --git tests/phpunit/data/images/orientation-5.jpg tests/phpunit/data/images/orientation-5.jpg new file mode 100644 index 0000000..81a8af6 Binary files /dev/null and tests/phpunit/data/images/orientation-5.jpg differ diff --git tests/phpunit/data/images/orientation-6.jpg tests/phpunit/data/images/orientation-6.jpg new file mode 100644 index 0000000..7426aba Binary files /dev/null and tests/phpunit/data/images/orientation-6.jpg differ diff --git tests/phpunit/data/images/orientation-7.jpg tests/phpunit/data/images/orientation-7.jpg new file mode 100644 index 0000000..a541d95 Binary files /dev/null and tests/phpunit/data/images/orientation-7.jpg differ diff --git tests/phpunit/data/images/orientation-8.jpg tests/phpunit/data/images/orientation-8.jpg new file mode 100644 index 0000000..3f51d28 Binary files /dev/null and tests/phpunit/data/images/orientation-8.jpg differ diff --git tests/phpunit/tests/image/orientation.php tests/phpunit/tests/image/orientation.php new file mode 100644 index 0000000..fef05e1
- + 1 <?php 2 require_once dirname( __FILE__ ) . '/base.php'; 3 4 /** 5 * Test the WP_Image_Editor base class 6 * 7 * @group image 8 * @group media 9 */ 10 class Tests_Image_Editor_Orientation extends WP_Image_UnitTestCase { 11 12 public $editor_engine = 'WP_Image_Editor_Imagick'; 13 14 public function setUp() { 15 require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' ); 16 require_once( ABSPATH . WPINC . '/class-wp-image-editor-imagick.php' ); 17 18 parent::setUp(); 19 } 20 21 /** 22 * Test removing orientation exif data on rotate 23 * 24 * @ticket 37140 25 * 26 * @dataProvider get_images 27 */ 28 public function test_remove_orientation_data_on_rotate( $file ) { 29 30 preg_match( '/-(\d)\.(?:jpe?g|png|gif)$/', $file, $matches ); 31 $orientation_value = intval( $matches[1] ); 32 33 $data = wp_read_image_metadata( $file ); 34 35 $this->assertEquals( $orientation_value, intval( $data['orientation'] ), 'Orientation value read from does not match image file exif data: ' . $file ); 36 37 $temp_file = wp_tempnam( $file, 'image-tests' ) . '.jpg'; 38 39 $image = wp_get_image_editor( $file ); 40 $image->rotate( 180 ); 41 $image->save( $temp_file ); 42 43 $data = wp_read_image_metadata( $temp_file ); 44 45 $this->assertEquals( 1, intval( $data['orientation'] ), 'Orientation exif data was not updated after rotating image: ' . $file ); 46 47 unlink( $temp_file ); 48 } 49 50 /** 51 * dataProvider for images 52 */ 53 public function get_images() { 54 return array_map( function ( $num ) { 55 return array( DIR_TESTDATA . "/images/orientation-{$num}.jpg" ); 56 }, range( 1, 8 ) ); 57 } 58 59 }