Unverified Commit 09a59423 authored by T.J.  Hellmann's avatar T.J. Hellmann Committed by Lucas Hedding
Browse files

Issue #3284307 by a.milkovsky, vselivanov, tjhellmann, heddn: Add remote file...

Issue #3284307 by a.milkovsky, vselivanov, tjhellmann, heddn: Add remote file system support (like S3)
parent dabc2dd7
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManager;
use Drupal\file\FileInterface;

/**
@@ -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'])) {