diff --git a/core/lib/Drupal/Core/Image/Image.php b/core/lib/Drupal/Core/Image/Image.php index 1eaf966..e41bd3e 100644 --- a/core/lib/Drupal/Core/Image/Image.php +++ b/core/lib/Drupal/Core/Image/Image.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Image; +use Drupal\Core\ImageToolkit\ImageToolkitExifInterface; use Drupal\Core\ImageToolkit\ImageToolkitInterface; /** @@ -17,7 +18,7 @@ * * @ingroup image */ -class Image implements ImageInterface { +class Image implements ImageInterface, ImageExifInterface { /** * Path of the image file. @@ -107,14 +108,20 @@ public function getSource() { * {@inheritdoc} */ public function getExif($tag = NULL) { - return $this->getToolkit()->getExif($tag); + if ($this->getToolkit() instanceof ImageToolkitExifInterface) { + return $this->getToolkit()->getExif($tag); + } + return NULL; } /** * {@inheritdoc} */ public function getExifStatus() { - return $this->getToolkit()->getExifStatus(); + if ($this->getToolkit() instanceof ImageToolkitExifInterface) { + return $this->getToolkit()->getExifStatus(); + } + return NULL; } /** diff --git a/core/lib/Drupal/Core/Image/ImageExifInterface.php b/core/lib/Drupal/Core/Image/ImageExifInterface.php new file mode 100644 index 0000000..c021184 --- /dev/null +++ b/core/lib/Drupal/Core/Image/ImageExifInterface.php @@ -0,0 +1,56 @@ +exifData; } - else { - return $tag ? NULL : $this->exifData; - } + + return NULL; } /** @@ -176,7 +175,7 @@ protected function parseExifData() { // Check if function is available. if (!function_exists('exif_read_data')) { // No PHP EXIF extension enabled, return. - $this->logger->error('The PHP EXIF extension is not installed. The image toolkit is unable to determine image orientation.'); + $this->logger->error('The PHP EXIF extension is not installed. The image toolkit is unable to retrieve image EXIF data.'); $this->setExifData([], static::EXIF_NO_PHP_EXTENSION); return $this; } diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitExifInterface.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitExifInterface.php new file mode 100644 index 0000000..79c8936 --- /dev/null +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitExifInterface.php @@ -0,0 +1,101 @@ +getToolkit()->setExifData([], ImageToolkitInterface::EXIF_RESET); + $this->getToolkit()->setExifData([], ImageToolkitExifInterface::EXIF_RESET); } return TRUE; diff --git a/core/tests/Drupal/Tests/Core/Image/ImageTest.php b/core/tests/Drupal/Tests/Core/Image/ImageTest.php index f53d5c6..7b82745 100644 --- a/core/tests/Drupal/Tests/Core/Image/ImageTest.php +++ b/core/tests/Drupal/Tests/Core/Image/ImageTest.php @@ -8,6 +8,7 @@ namespace Drupal\Tests\Core\Image; use Drupal\Core\Image\Image; +use Drupal\Core\ImageToolkit\ImageToolkitExifInterface; use Drupal\Core\ImageToolkit\ImageToolkitInterface; use Drupal\Tests\UnitTestCase; @@ -290,26 +291,26 @@ public function testParseFileFails() { public function testExif() { // Test a PNG image (not EXIF enabled). $this->getTestImage(); - $this->assertEquals(ImageToolkitInterface::EXIF_NOT_PARSED, $this->image->getExifStatus()); + $this->assertEquals(ImageToolkitExifInterface::EXIF_NOT_PARSED, $this->image->getExifStatus()); $this->assertNull($this->image->getExif('Orientation')); - $this->assertEquals(ImageToolkitInterface::EXIF_UNSUPPORTED_FORMAT, $this->image->getExifStatus()); + $this->assertEquals(ImageToolkitExifInterface::EXIF_UNSUPPORTED_FORMAT, $this->image->getExifStatus()); $this->assertNull($this->image->getExif('FileName')); $this->assertEquals([], $this->image->getExif()); // Test a JPEG image without EXIF data. $source = __DIR__ . '/../../../../../modules/simpletest/files/image-test.jpg'; $this->getTestImage(TRUE, [], $source); - $this->assertEquals(ImageToolkitInterface::EXIF_NOT_PARSED, $this->image->getExifStatus()); + $this->assertEquals(ImageToolkitExifInterface::EXIF_NOT_PARSED, $this->image->getExifStatus()); $this->assertNull($this->image->getExif('Orientation')); - $this->assertEquals(ImageToolkitInterface::EXIF_PARSED_OK, $this->image->getExifStatus()); + $this->assertEquals(ImageToolkitExifInterface::EXIF_PARSED_OK, $this->image->getExifStatus()); $this->assertEquals('image-test.jpg', $this->image->getExif('FileName')); // Test a JPEG image with EXIF data. $source = __DIR__ . '/../../../../../modules/simpletest/files/image-test-exif.jpeg'; $this->getTestImageForOperation('CreateNew', [], $source); - $this->assertEquals(ImageToolkitInterface::EXIF_NOT_PARSED, $this->image->getExifStatus()); + $this->assertEquals(ImageToolkitExifInterface::EXIF_NOT_PARSED, $this->image->getExifStatus()); $this->assertEquals(8, $this->image->getExif('Orientation')); - $this->assertEquals(ImageToolkitInterface::EXIF_PARSED_OK, $this->image->getExifStatus()); + $this->assertEquals(ImageToolkitExifInterface::EXIF_PARSED_OK, $this->image->getExifStatus()); $this->assertEquals('106/32', $this->image->getExif('ShutterSpeedValue')); $expected_thumbnail = [ 'Compression' => 6, @@ -325,7 +326,7 @@ public function testExif() { // Test resetting EXIF data via createNew. $this->image->createNew(200, 200); - $this->assertEquals(ImageToolkitInterface::EXIF_RESET, $this->image->getExifStatus()); + $this->assertEquals(ImageToolkitExifInterface::EXIF_RESET, $this->image->getExifStatus()); $this->assertEquals([], $this->image->getExif()); }