Bug #69274

Portrait Images rotated while file processing

Added by Philipp Wrann over 5 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Should have
Category:
File Abstraction Layer (FAL)
Target version:
-
Start date:
2015-08-24
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
7
PHP Version:
5.6
Tags:
Complexity:
easy
Is Regression:
No
Sprint Focus:

Description

Many cameras today save pictures not rotated when making a portrait, they save it with some exif meta tag that turns the image in preview mode (90|180|270 deg).

Typo3 should take this into account after uploading. One of my customer has to rotate many pictures in preview program of OS to make it appear correctly in TYPO3.

Either rotate the image:

Imagemagicks convert has some -auto-orient option, that should do the job.
Here is some resource:
http://stackoverflow.com/questions/19456036/detect-exif-orientation-and-rotate-image-using-imagemagick

Or take the exif-information simply into account in all places and provide optionally a button to reset it (like in preview programs).


Files

Exif Left Bottom Test Image.JPG (1.02 MB) Exif Left Bottom Test Image.JPG Markus Klein, 2018-05-18 15:45

Related issues

Related to TYPO3 Core - Bug #61655: Image rescaling breaks/ignores exif orientationClosed2014-09-16

Actions
#1

Updated by Xavier Perseguers over 5 years ago

  • Status changed from New to Rejected

This is not a bug, when you upload an image, the Core of TYPO3 should not do any magick because changing the orientation modifies the actual image you uploaded.

However, there is an easy solution for that, just install EXT:image_autoresize from TER and it will do exactly that (if you don't want to reduce size of uploaded images at all - why?) then just put some very high size threshold in the configuration.

#2

Updated by Philipp Wrann over 5 years ago

I will have a look at that extension but why would it be so bad to include some functionality in the core? Or to simply make use of the orientation exif information?

At the moment you upload a portrait image (taken from iphone) and the image is displayed rotated - if the exif orientation is set it should be taken into account when creating processed images, dont you think?

IMO this should really work out of the box.

So okay - imagemagick convert is no solution - but taking the exif rotate property into account when dealing with images IS.

#3

Updated by Christiaan Wiesenekker over 5 years ago

I think Philipp Wrann is totally right. Ignoring the orientation IS doing magic to the original file... TYPO3 core should respect the exif's

#4

Updated by Mr Fondolz about 5 years ago

Why was this bug rejected? It is an issue how typo3 is using image magick. It should be atleast a setting in the [GFX] part of the installer. Using or developing an extension for this basic functionallity is too much....

I currently use the option [GFX][im_useStripProfileByDefault] so i can use [GFX][im_stripProfileCommand] with "-auto-orient +profile '*'" and every uploaded image will be fine.

#5

Updated by Xavier Perseguers about 5 years ago

For the record, ImageMagick is known to be much more vulnerable than GraphicsMagick and you may have a look into the code from EXT:image_autoresize how I had to handle the reorientation when using GM, this is not a simple flag as in IM. Furthermore, this is definitely magick to modify the file when uploading. Taking the EXIF orientation into account, when displaying the image, is not the same as changing the file. When you rotate the picture, you are potentially changing its quality as well, since the pattern in JPEG chunks are not the same anymore.

Long story short, there are a few easy solutions that you came with:

  • Install EXT:image_autoresize
  • Modify the im_useStripProfileByDefault setting which works fine if you use IM

I don't see a need to do anything else in the Core.

#6

Updated by Stefan Froemken about 5 years ago

  • Subject changed from Portrait Images rotated after uploading to Portrait Images rotated while file processing
  • Status changed from Rejected to Accepted
  • Assignee set to Stefan Froemken
  • Target version changed from 7.5 to 7.6.5
  • PHP Version set to 5.6
  • Complexity set to easy

As already told, we will not modify any file while upload.
But we can modify the thumb and image generation for Backend and Frontend.
I have changed the title and will create a new patch to add the new option in Installtool

#7

Updated by Gerrit Code Review about 5 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/48079

#8

Updated by Gerrit Code Review about 5 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/48079

#9

Updated by Benni Mack almost 5 years ago

  • Target version changed from 7.6.5 to Candidate for patchlevel
#10

Updated by Ruben Schmidmeister almost 5 years ago

Setting -auto-orient alone will only partially fix this issue, because the width/height calculation for image resizing still ignores the EXIF rotation.
Replacing calls to the PHP function getimagesize with a custom function would fix the problem:

class ImageUtility
{
    /**
     * @param string $imageFile
     *
     * @return array
     */
    public static function getImageSize($imageFile)
    {
        $size = @getimagesize($imageFile);

        if ($size === FALSE) {
            return FALSE;
        }

        $exif = @exif_read_data($imageFile);

        $width = $size[ 0 ];
        $height = $size[ 1 ];

        // see: http://sylvana.net/jpegcrop/exif_orientation.html
        if (isset($exif[ 'Orientation' ]) && $exif[ 'Orientation' ] >= 5 && $exif[ 'Orientation' ] <= 8) {
            return [$height, $width];
        }

        return [$width, $height];
    }
}

I have experimented with an extension that overrides the following methods from the core:
(only replaces calls to getimagesize with the function shown above)

  • \TYPO3\CMS\Core\Imaging\GraphicalFunctions->getImageDimensions
  • \TYPO3\CMS\Core\Imaging\GraphicalFunctions->imageCreateFromFile
  • \TYPO3\CMS\Core\Type\File\ImageInfo->getImageSizes

and the images seem to be processed correctly.

#11

Updated by Markus Klösges over 3 years ago

I also got caught by this. Exif rotation is applied if the corresponding flag is set in LocalConfiguration, but using such a rotated file inside of GIFBUILDER leads to wrong output dimensions. @Ruben, I tried your solution without luck, do you have any newer input on that issue?

#12

Updated by Ruben Schmidmeister over 3 years ago

@Markus Since posting that comment I have fixing the behavior of the image processing might not be the best solution.
(Browsers display images with an EXIF orientation incorrectly so we would have to process all those images to make sure the images are displayed properly.)

( Shameless self-advertising ahead ;-) )
However, I did create an extension that creates a button to "apply" the EXIF orientation on such images: https://github.com/bash/exif_orientation_helper

#13

Updated by Gerrit Code Review over 3 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/48079

#14

Updated by Gerrit Code Review over 3 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/48079

#15

Updated by Gerrit Code Review over 3 years ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/48079

#16

Updated by Riccardo De Contardi over 3 years ago

  • Related to Bug #61655: Image rescaling breaks/ignores exif orientation added
#17

Updated by Gerrit Code Review over 3 years ago

Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/48079

#18

Updated by Benni Mack over 3 years ago

  • Sprint Focus set to On Location Sprint
#19

Updated by Tomas Norre Mikkelsen over 3 years ago

I've been considering this issue.. and from my point of view this is a task for the editors not for the CMS.. Of course it would be nice if the system supports the editors, but images are always a little sensitive topic.

It's content and it has to be verified by the Editor anyway.. I wouldn't invest more time in this.

I would reject this issue.

#20

Updated by Markus Timtner over 3 years ago

At least the image editing tool should offer the option to rotate images -
it is something a user would expect if a tool calls itself image "editor"
Nearly all of my editors are complaining about the missing rotation option.
(or the image editing tool should be called "cropping tool" otherwise.)

@#12 Ruben Schmidmeister
Thank you very much for your work, will have a look into that.

#21

Updated by Gerrit Code Review about 3 years ago

Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/48079

#22

Updated by Gerrit Code Review about 3 years ago

Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/48079

#23

Updated by Gerrit Code Review about 3 years ago

Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/48079

#24

Updated by Mathias Brodala about 3 years ago

  • Sprint Focus deleted (On Location Sprint)
#25

Updated by Gerrit Code Review almost 3 years ago

Patch set 10 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/48079

#26

Updated by Gerrit Code Review almost 3 years ago

Patch set 11 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/48079

#27

Updated by Gerrit Code Review almost 3 years ago

Patch set 12 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/48079

#28

Updated by Markus Klein almost 3 years ago

#29

Updated by Stefan Froemken almost 3 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
#30

Updated by Benni Mack over 2 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF