Bug #69274

Portrait Images rotated while file processing

Added by Philipp Wrann almost 4 years ago. Updated 8 months ago.

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

100%

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).

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


Related issues

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

Associated revisions

Revision 5179ff93 (diff)
Added by Stefan Froemken about 1 year ago

[FEATURE] Preserve image rotation if orient is saved in exif

Some digicams like iPhone do not rotate images
by default. They add a direction entry into the exif
meta data.

ImageMagick can read this entry if -auto-orient is set.

The patch add the rotation detection to the ImageInfo object and the
IM/GD commands that read files.

Resolves: #69274
Releases: master
Change-Id: I4b1193daf1c321a3d4beb8d76974012ee42470f6
Reviewed-on: https://review.typo3.org/48079
Tested-by: TYPO3com <>
Reviewed-by: Frans Saris <>
Tested-by: Frans Saris <>
Reviewed-by: Markus Klein <>
Tested-by: Markus Klein <>

History

#1 Updated by Xavier Perseguers almost 4 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 almost 4 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 3 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 3 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 3 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 3 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 3 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 3 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 3 years ago

  • Target version changed from 7.6.5 to Candidate for patchlevel

#10 Updated by Ruben Schmidmeister almost 3 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 1 year 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 1 year 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 1 year 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 1 year 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 1 year 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 1 year ago

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

#17 Updated by Gerrit Code Review over 1 year 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 1 year ago

  • Sprint Focus set to On Location Sprint

#19 Updated by Tomas Norre Mikkelsen over 1 year 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 1 year 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 1 year 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 1 year 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 1 year 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 1 year ago

  • Sprint Focus deleted (On Location Sprint)

#25 Updated by Gerrit Code Review about 1 year 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 about 1 year 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 about 1 year 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 about 1 year ago

#29 Updated by Stefan Froemken about 1 year ago

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

#30 Updated by Benni Mack 8 months ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF