Problem/Motivation

Images are being uploaded that are rotated if they are portrait. Most of the image sizes are shown as flipped for these images in the IMCE file manager. This was first noticed after upgrade to IMCE 8.x-2.3. There is no rotation if the photo has been saved with an app (such as Photoshop) prior to upload.

Steps to reproduce

  1. Open IMCE file manager.
  2. Upload a portrait orientation photo that has not be edited (such as from a phone).
  3. After upload is complete, note that that portrait photo is now rotated 90 degrees.

Proposed resolution

I believe this has to do with the exif information not being read by IMCE. I'm not sure what happened with this new version, or if the problem may be with Drupal itself as we noticed the issue with any such image upload. We are using exif_orientation module to fix regular image uploads (not with IMCE), but it doesn't work with uploading via IMCE.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

fredonia_webteam created an issue. See original summary.

ufku’s picture

Status: Active » Closed (won't fix)

You may consider using https://www.drupal.org/project/exif_orientation for all uploads across the site. However if you are limiting the max image dimensions on upload it may not work because the resizing takes place before exif_orientation fixes the image. https://www.drupal.org/project/exif_orientation/issues/2344175

jrb’s picture

Status: Closed (won't fix) » Needs work
StatusFileSize
new759 bytes
new1.3 KB

This really is a problem with IMCE that can't be solved by using the EXIF Orientation module due to the way that IMCE sets the the file validators. EXIF Orientation works by either:

1. Adding a validator function before the file_validate_image_resolution() validator with a hook_field_widget_form_alter() that will rotate the image.
2. Using a hook_file_presave() to do the rotation as the image is saved.

These won't work with IMCE because (1) IMCE doesn't use form validators and (2) it's too late by the time presave is run because the EXIF data has already been stripped.

This could be fixed in IMCE in ImcePlugin::opUpload() in a couple different ways:

1. We could check if EXIF Orientation is enabled and add its validator function first.

$validators = [];
// If exif_orientation is enabled, use its validator.
if (\Drupal::service('module_handler')->moduleExists('exif_orientation')) {
  $validators['exif_orientation_validate_image_rotation'] = [];
}
// Extension validator.
$exts = $fm->getConf('extensions', '');
$validators['file_validate_extensions'] = [$exts === '*' ? NULL : $exts];

2. More generally, we could add support for hook_imce_file_upload_validators_alter() functions:

// Name validator.
$validators[get_class($this) . '::validateFileName'] = [$fm];
// Allow other modules to alter the validator functions.
\Drupal::moduleHandler()->alter('imce_file_upload_validators', $validators);
// Save files.
if ($files = file_save_upload('imce', $validators, $destination, NULL, $replace)) {

Then, EXIF Orientation (or a custom module) would need to implement its own exif_orientation_imce_file_upload_validators_alter() function to add exif_orientation_validate_image_rotation() to $validators.

Either of these would allow EXIF Orientation (or other modules) to do its thing.

I've attached patches for each of these. If you wanted to do #2, we'd need to add an issue/patch to EXIF Orientation, too.

  • ufku committed ff27848 on 8.x-2.x
    Issue #3202362: Fix exif orientation before resizing
    
ufku’s picture

Version: 8.x-2.3 » 8.x-2.x-dev
Status: Needs work » Fixed

Added exif_orientation_validate_image_rotation as a validator before file_validate_image_resolution

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.