Add EXIF Orientation upload process

Created on 10 June 2021, about 3 years ago
Updated 24 May 2023, over 1 year ago

Problem/Motivation

Having an Orientation rotate with image been uploaded from iPhones, iPads, and some other cameras
Which they look right on the original machine.
But when moved to other devices and systems. they will look with the original orientation without the the extra file attribute.

Steps to reproduce

Given that Varbase profile was installed on a remote server
And number of images/pictures had been taken with an orientation
And files been passed to an editor to upload them to the website
When uploading asset files
Then the uploaded image file and all exit image style will have a wrong rotation

Proposed resolution

Rotates an image to its EXIF Orientation.

iPhone 4 and up save all images in landscape, relying on EXIF data to
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...

function _exif_orientation_rotate($file) {
  if (function_exists('exif_read_data') && $file->getMimeType() == 'image/jpeg') {
    $file_exif = @exif_read_data(\Drupal::service('file_system')->realpath($file->getFileUri()));

    // Ensure that the Orientation key|value exists, otherwise leave.
    if (!is_array($file_exif) || !isset($file_exif['Orientation'])) {
      return;
    }

    // Orientation numbers and corresponding degrees.
    // @note: Odd numbers are flipped images, would need different process.
    switch ($file_exif['Orientation']) {
      case 3:
        $degrees = 180;
        break;

      case 6:
        $degrees = 90;
        break;

      case 8:
        $degrees = 270;
        break;

      default:
        $degrees = 0;
    }

    if ($degrees > 0) {
      $image = \Drupal::service('image.factory')->get($file->getFileUri());
      if ($image->rotate($degrees)) {
        $image->save();
      }
    }
  }

Remaining tasks

  • ✅ File an issue about this project
  • ❌ Add EXIF Orientation module
  • ❌ Testing to ensure no regression
  • ❌ Automated unit/functional testing coverage
  • ❌ Developer Documentation support on feature change/addition
  • ❌ User Guide Documentation support on feature change/addition
  • ❌ Code review from 1 Varbase core team member
  • ❌ Full testing and approval
  • ❌ Credit contributors
  • ❌ Review with the product owner
  • ❌ Release

User interface changes

  • Have the right image orientation rotation on upload, with no need of editing images before upload.

API changes

  • None

Data model changes

  • Rotate the image or save the file attribute
Feature request
Status

Active

Version

10.0

Component

Code

Created by

🇯🇴Jordan Omar Alahmed Jordan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024