Jump to content
Mikael

image rotation is on wrong direction

Recommended Posts

Hi community! Thank you for the great system!

But I have faced with a problem. Given an image. When I upload the image to image field - image gets rotation in wrong direction..

 

1920695795_Screenshotfrom2020-12-0212-59-49.png.64e89e6a25fc348a31cd85525d2c8683.png

 

On the above image you can see the third image rotated on the contrary...

https://github.com/processwire/processwire/blob/d8945198f4a6a60dab23bd0462e8a6285369dcb9/wire/core/ImageSizerEngineGD.php#L477

DSC01828.zipAlso if I change the above line to:

$angle = 360 + $degree;

then it rotates it correct.. So it seems like script rotates image in wrong direction.. What to do with that? Thanks!

I have attached zip with original image.DSC01828.zip

Share this post


Link to post
Share on other sites

@bernhard thank you for the answer! I have commented it on github) But how do you avoid this problem for your own ?

How do you think, it is good idea to avoid it as I said, at least temporary with changing '-' to '+'

$angle = 360 + $degree;

Share this post


Link to post
Share on other sites

I have no solution yet. @Robin S seems to have found a way, but I had no time to test what he wrote in the issue. I was always hoping that Ryan will come up with a fix sooner than I have to build a quickfix on my own. I thought of adding custom buttons/checkboxes to rotate the image after saving... For now I've just added a comment that says "if the orientation is wrong please use this online editor and upload the image again" 😞 

Share this post


Link to post
Share on other sites

@bernhard But where can I take a look at Robin S solution ? I even did not expect that meeting brother in misfortune could make me so happy. Your web site looks great. We are also a German team. Our link will be encrypted in this message, like a little puzzle) So need to fix it and 'get it work'.. I don't know if the extension of website where I have error with image does matter, but if it does it is 'com'. 

Share this post


Link to post
Share on other sites

@Robin S is a genius! 🙂 

Based on his posts in the github issue I did the following and finally got the bug fixed (it seems):

 

For Server Side Resizing:

Search for "$corrections = array(" in all your files. You should find 3 files:

YXjQreP.png

Replace those arrays with this one:

		$corrections = array(
			'1' => array(0, 0),
			'2' => array(0, 1),
			'3' => array(180, 0),
			'4' => array(0, 2),
			'5' => array(90, 1),
			'6' => array(90, 0),
			'7' => array(270, 1),
			'8' => array(270, 0)
		);

This did already fix my issue.

Client Side:

Replace PWImageResizer.js with this file created by @Robin S and delete the old minified version PWImageResizer.min.js to make sure that the new version is loaded: https://github.com/processwire/processwire-issues/files/4660217/PWImageResizer.zip

 

Would be great to hear if that also fixed your issue @Mikael ?

Thx again @Robin S for the great work!!

  • Like 1

Share this post


Link to post
Share on other sites

@bernhard wow wow really wow) I followed your instruction and seems problem gone away ) Hope it will not back again) Great danke! 

Share this post


Link to post
Share on other sites
1 minute ago, Mikael said:

Hope it will not back again)

It will be back on the next update of ProcessWire unless Ryan fixes the issue in the core until then. So you either need to wait with that update or you apply the changes again after your upgrade.

Share this post


Link to post
Share on other sites

@bernhard yes this is completely understandable ) but I meant that bug will not have other side effects and not appear with other images 

Share this post


Link to post
Share on other sites

What I do not understand is why the original code has worked for 15+ years and now (within a sudden) it should not do anymore. As far as I could not find any changes in the EXIF specs. ??

Are you sure that the corrections arrays are wrong, really? Or may it be that the browsers have changed to a behave that rotates images ONLY BY VIEW, and that this new browser behave has to be corrected elsewhere in the inspection and processing workflow?

Just wondering.

  • Like 1

Share this post


Link to post
Share on other sites

Yeah, good point. I have no idea... I have another problem in my app. I'm generating a PDF from a page with some images and one of them keeps getting rotated by 90°. Only one, all the other images work as expected. 😞 

Share this post


Link to post
Share on other sites

Until today, since 20+ years, every time when I inspected such behaves, it comes out at 100% that the source image simply got the wrong notation in the EXIF rotation flag. 

Mostly directly when created from a camera, but also came from image tools that rotated images without updating the EXIF rotation flag.

In my opinion, the new browser behave isn't of any help but makes it more "mysterious" for regular users when working within image processing chains. The ONLY point where this new behave is helpful is when original images will be displayed on the front in a webpage (and have uncorrected rotation).

Share this post


Link to post
Share on other sites

Hm. I thought maybe I could strip the EXIF data from the image but did not have enough time to look into it. Do you know if PW has a method for that? Otherwise it seems to be 7 lines of code using php+imagick (which I'm using).

Share this post


Link to post
Share on other sites

EXIF data is stripped out with every processing function that uses GD-lib. So, if you just use creating a 100% width "variation" and store it as the "new" original image, all your EXIF data is lost. (GD-lib simply does not keep any image markers by design. Historically it was build to create small images for the web, and everything that may bloat filesize is dropped)

PW every time reads the EXIF data from the original image that regularly will be kept untouched.

  • Thanks 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...