Issue with product image keeps rotating

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
aimeosenv
Posts: 7
Joined: 13 Dec 2022, 21:04

Issue with product image keeps rotating

Post by aimeosenv » 13 Dec 2022, 21:37

Hello,

I'm a new Aimeos (Laravel version) user and I'm starting to really love it and the way it's been put together.
There are few things that took me a while to grasp, but I'm getting there. :)

Now, when it comes to the issue that I'm having now, it's one with product image upload.
I have consulted documentation and did a lot of testing and playing around with settings, no matter what I do and what type of settings I pass along in:
vendor/aimeos/aimeos-core/config/controller.php
Image taken directly from phone keeps getting ROTATED. Resizing is done properly, everything that I set in options is being applied, only highly annoying thing is that image keeps ROTATING.

Rotation is 90 degrees counterclockwise.

I would like to point out that PREVIEW image (first one that shows once image is uploaded) is fine.
Rotating occurs once when "Save" button is clicked and action performed.

Is there option in the media processing part or controller.php that just can say "do not rotate images". Do resizing and whatever is needed, but stop rotating.

Image size (if it matters):
Width: 2604
Height: 4624

If image goes trough Photoshop and is saved, it does not keep rotating. If it is downloaded from IG (for example) and uploaded it does not rotate. One really really odd situation or possible bug.

Any input is appreciated. Thanks all for reading and help!

Aimeos 2022.10+ (2022.10.3)
PHP 8.1.12
Win
============================
Aimeos 2022.10+ (2022.10.3)
PHP 8.1.12 / Laravel
Win (Develop)

User avatar
aimeos
Administrator
Posts: 7881
Joined: 01 Jan 1970, 00:00

Re: Issue with product image keeps rotating

Post by aimeos » 14 Dec 2022, 07:09

Hm, Aimeos doesn't implement rotating images at all, only resizing and cropping can be done.
Maybe it's something that is done by Imagemagick automatically?

Here's the source code for image handling:
https://github.com/aimeos/aimeos-core/b ... magick.php
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

aimeosenv
Posts: 7
Joined: 13 Dec 2022, 21:04

Re: Issue with product image keeps rotating

Post by aimeosenv » 15 Dec 2022, 12:04

Thanks for your reply. Yes that seems to be the case.

Here is one very old post, but it does explain this type of behavior and helped me with further research.

I have just read EXIF of one of the uploaded files and indeed it says clearly:

Code: Select all

Orientation: Rotate 90 CW
It seems to me that photo is taken horizontally with instructions to rotate it 90 CW written in EXIF that seems not to be applied when process is completed.

Imagick.php that handles images does not take this into consideration and it actually uses image "as is" (horizontal) without this instruction to rotate it 90 CW. However, preview image does use it and applies rotate 90 CW to the image properly.
============================
Aimeos 2022.10+ (2022.10.3)
PHP 8.1.12 / Laravel
Win (Develop)

aimeosenv
Posts: 7
Joined: 13 Dec 2022, 21:04

Re: Issue with product image keeps rotating

Post by aimeosenv » 15 Dec 2022, 15:07

Quick update.

I have done a quick test. Updating this code here:
https://github.com/aimeos/aimeos-core/b ... k.php#L129

Inserting:

Code: Select all

        $orientation = $this->image->getImageOrientation();

        switch($orientation) {

            case 6:
                $this->image->rotateImage("#fff", 90); // rotate 90 degrees CW
                break;


        }

        // Now that it's auto-rotated, make sure the EXIF data is correct in case the EXIF gets saved with the image!
        $this->image->setImageOrientation(1);
Solves issue for our use case. I will do other cases as well, but this was just a quick test and it works. :)

Ref:
https://www.php.net/manual/en/imagick.g ... php#111448
https://exiftool.org/forum/index.php?topic=7909.0
============================
Aimeos 2022.10+ (2022.10.3)
PHP 8.1.12 / Laravel
Win (Develop)

User avatar
aimeos
Administrator
Posts: 7881
Joined: 01 Jan 1970, 00:00

Re: Issue with product image keeps rotating

Post by aimeos » 17 Dec 2022, 09:57

Very cool and eager to get a PR from you solving that issue! :-)
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

aimeosenv
Posts: 7
Joined: 13 Dec 2022, 21:04

Re: Issue with product image keeps rotating

Post by aimeosenv » 17 Dec 2022, 18:46

Thanks for checking it out and confirming that this is a right place to do so! Will do as soon as I sort it out. :)
============================
Aimeos 2022.10+ (2022.10.3)
PHP 8.1.12 / Laravel
Win (Develop)

Post Reply