Loading exif_orientation.module +20 −4 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\StreamWrapper\StreamWrapperManager; use Drupal\file\FileInterface; /** Loading Loading @@ -54,18 +55,33 @@ function exif_orientation_validate_image_rotation(FileInterface $file) { * set the orientation properly. This does not always translate well in the * browser or other devices. * @link: http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ * * @param \Drupal\file\FileInterface $file * File entity. */ function _exif_orientation_rotate($file) { function _exif_orientation_rotate(FileInterface $file) { $mime_types = ['image/jpeg', 'image/png']; if (function_exists('exif_read_data') && in_array($file->getMimeType(), $mime_types)) { $realPath = \Drupal::service('file_system')->realpath($file->getFileUri()); if ($realPath === FALSE) { $uri = $file->getFileUri(); // Can't get stream wrapper if URI is without scheme. if (!StreamWrapperManager::getScheme($uri)) { return; } /** @var \Drupal\Core\StreamWrapper\StreamWrapperInterface $wrapper */ $wrapper = \Drupal::service('stream_wrapper_manager')->getViaUri($uri); $path = $wrapper->realpath(); if (empty($path)) { $path = $wrapper->getExternalUrl(); } if (!$path) { return; } $file_exif = @exif_read_data($realPath); $file_exif = @exif_read_data($path); // Ensure that the Orientation key|value exists, otherwise leave. if (!is_array($file_exif) || !isset($file_exif['Orientation'])) { Loading Loading
exif_orientation.module +20 −4 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\StreamWrapper\StreamWrapperManager; use Drupal\file\FileInterface; /** Loading Loading @@ -54,18 +55,33 @@ function exif_orientation_validate_image_rotation(FileInterface $file) { * set the orientation properly. This does not always translate well in the * browser or other devices. * @link: http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ * * @param \Drupal\file\FileInterface $file * File entity. */ function _exif_orientation_rotate($file) { function _exif_orientation_rotate(FileInterface $file) { $mime_types = ['image/jpeg', 'image/png']; if (function_exists('exif_read_data') && in_array($file->getMimeType(), $mime_types)) { $realPath = \Drupal::service('file_system')->realpath($file->getFileUri()); if ($realPath === FALSE) { $uri = $file->getFileUri(); // Can't get stream wrapper if URI is without scheme. if (!StreamWrapperManager::getScheme($uri)) { return; } /** @var \Drupal\Core\StreamWrapper\StreamWrapperInterface $wrapper */ $wrapper = \Drupal::service('stream_wrapper_manager')->getViaUri($uri); $path = $wrapper->realpath(); if (empty($path)) { $path = $wrapper->getExternalUrl(); } if (!$path) { return; } $file_exif = @exif_read_data($realPath); $file_exif = @exif_read_data($path); // Ensure that the Orientation key|value exists, otherwise leave. if (!is_array($file_exif) || !isset($file_exif['Orientation'])) { Loading