Project

General

Profile

Actions

Bug #69274

closed

Portrait Images rotated while file processing

Added by Philipp Wrann over 8 years ago. Updated over 5 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 2 (0 open2 closed)

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

Actions
Related to TYPO3 Core - Task #101922: Suggest php exif module in system environment statusClosedTorben Hansen2023-09-14

Actions
Actions #1

Updated by Xavier Perseguers over 8 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.

Actions #2

Updated by Philipp Wrann over 8 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.

Actions #3

Updated by Christiaan Wiesenekker over 8 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

Actions #4

Updated by Mr Fondolz almost 8 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.

Actions #5

Updated by Xavier Perseguers almost 8 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.

Actions #6

Updated by Stefan Froemken almost 8 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

Actions #7

Updated by Gerrit Code Review almost 8 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

Actions #8

Updated by Gerrit Code Review almost 8 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

Actions #9

Updated by Benni Mack almost 8 years ago

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

Updated by Deleted Account almost 8 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.

Actions #11

Updated by Markus Klösges over 6 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?

Actions #12

Updated by Deleted Account over 6 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

Actions #13

Updated by Gerrit Code Review over 6 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

Actions #14

Updated by Gerrit Code Review over 6 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

Actions #15

Updated by Gerrit Code Review over 6 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

Actions #16

Updated by Riccardo De Contardi over 6 years ago

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

Updated by Gerrit Code Review over 6 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

Actions #18

Updated by Benni Mack over 6 years ago

  • Sprint Focus set to On Location Sprint
Actions #19

Updated by Tomas Norre Mikkelsen over 6 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.

Actions #20

Updated by Markus Timtner over 6 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.

Actions #21

Updated by Gerrit Code Review about 6 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

Actions #22

Updated by Gerrit Code Review about 6 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

Actions #23

Updated by Gerrit Code Review about 6 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

Actions #24

Updated by Mathias Brodala about 6 years ago

  • Sprint Focus deleted (On Location Sprint)
Actions #25

Updated by Gerrit Code Review almost 6 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

Actions #26

Updated by Gerrit Code Review almost 6 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

Actions #27

Updated by Gerrit Code Review almost 6 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

Actions #28

Updated by Markus Klein almost 6 years ago

Actions #29

Updated by Stefan Froemken almost 6 years ago

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

Updated by Benni Mack over 5 years ago

  • Status changed from Resolved to Closed
Actions #31

Updated by Torben Hansen 7 months ago

  • Related to Task #101922: Suggest php exif module in system environment status added
Actions

Also available in: Atom PDF