autorotate module

122 views
Skip to first unread message

Jon Schewe

unread,
Oct 16, 2023, 11:07:57 AM10/16/23
to gallery...@googlegroups.com
I've used the autorotate module in the past and I recently noticed that uploaded images were rotated, but squished.

I went back through the list archives and found the advice to use GD instead of ImageMagick for graphics.  That got my images to have the correct aspect ration, but not be rotated.

I tried turning autorotate off and then on again and uploading a new image, however it isn't getting rotated. The small and medium resized images are not rotated and have the correct aspect ratio. The large image is rotated and has the aspect ratio of the original image.

Has anyone else had this issue? Do you have suggestions on fixes?

The gallery stats show
Version: 3.0+ (branch master, build 434) 
However it seems that the latest version didn't update these stats in the PHP file. This is the latest version that has been posted.

Jon


Jon Schewe

unread,
Mar 17, 2024, 10:06:51 PM3/17/24
to gallery...@googlegroups.com
I know it's been awhile since I asked this, does anyone have an answer to fix this? Or is the answer that I need to use a tool to rotate the images before upload?
--
WHEN USING AN EMAIL PROGRAM to reply to this message, click REPLY TO LIST or REPLY TO ALL so your reply goes out to everyone in the group. If you click REPLY or REPLY TO SENDER Google will *only* send your reply to the original author (not recommended).
 
To post a NEW MESSAGE to the group, send an new email to:
gallery...@googlegroups.com
 
To view or sign in to this group on the web, use this URL:
https://groups.google.com/forum/#!forum/gallery-3-users
---
You received this message because you are subscribed to the Google Groups "Gallery 3 Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gallery-3-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gallery-3-users/292a2dff480528140ed08c29205b217eb18ff375.camel%40mtu.net.

Adrian London

unread,
Mar 18, 2024, 5:50:26 AM3/18/24
to Gallery 3 Users
I'm not fully clear what's working and what isn't, as I find the sentence "The small and medium resized images are not rotated and have the correct aspect ratio. The large image is rotated and has the aspect ratio of the original image." a bit confusing.    It's early morning here and I've only just got my coffee :)

Anyway.  I only use my iPhone for photos now, and rotate all my photos before uploading them.  However, I just did a test and picked the ":rotate 90°" option from the "Photo Options" menu and it didn't work.  I checked the logs and a quick google tells me the GD module has changed in PHP 8.3 (which is what I use).  It might have changed in an earlier PHP 8.x version.

Easy fix.

In file ./system/libraries/drivers/Image/GD.php somewhere around line 292:

Change:
$img = imagerotate($img, 360 - $amount, $transparent, -1);

To
$img = imagerotate($img, 360 - $amount, $transparent);

Basically, a parameter that G3 passes to "imagerotate" has been obsoleted. 

I did a quick unix find|grep and didn't find any other calls to "imagerotate" so the change above will hopefully help.

Adrian London

unread,
Mar 18, 2024, 5:56:51 AM3/18/24
to Gallery 3 Users
Having re-read your sentence again, it seems that the rotation was working, but messing up the aspect ratio of the image.  So you probably have a different problem, and my solution isn't any use to you (yet - maybe you'll need it when you go to PHP 8.3!).

The original image - in /var/albums/blahblah is that also messed up?   When you select a photo and rotate it using the menu, does it work ok?  If so, then it's a problem local to the aurototate module.  If your individual rotation also fails then the issue is elsewhere/bigger.  Mine works, and it's one of the very few things I've never tinkered with.  The logs (var/logs) may say something useful.

Jon Schewe

unread,
Mar 18, 2024, 7:01:39 AM3/18/24
to gallery...@googlegroups.com
To be clear, after I upload a picture there are 3 versions available:

1 - thumbnail, this is seen when I look at the whole album
2 - medium sized, this is seen when I click on the thumbnail
3 - full sized, this is seen when I click on the medium sized

#1 and #2 are not rotated
#3 is rotated, however the aspect ratio is wrong

Note the last picture being a picture of the medal. It should be vertical. 


Clicking on #2 gives image #3, note how the aspect ratio is wrong?



On Mon, 2024-03-18 at 02:56 -0700, Adrian London wrote:
Having re-read your sentence again, it seems that the rotation was working, but messing up the aspect ratio of the image.  So you probably have a different problem, and my solution isn't any use to you (yet - maybe you'll need it when you go to PHP 8.3!).

The original image - in /var/albums/blahblah is that also messed up?   When you select a photo and rotate it using the menu, does it work ok?  If so, then it's a problem local to the aurototate module.  If your individual rotation also fails then the issue is elsewhere/bigger.  Mine works, and it's one of the very few things I've never tinkered with.  The logs (var/logs) may say something useful.

--
WHEN USING AN EMAIL PROGRAM to reply to this message, click REPLY TO LIST or REPLY TO ALL so your reply goes out to everyone in the group. If you click REPLY or REPLY TO SENDER Google will *only* send your reply to the original author (not recommended).
 
To post a NEW MESSAGE to the group, send an new email to:
gallery...@googlegroups.com
 
To view or sign in to this group on the web, use this URL:
https://groups.google.com/forum/#!forum/gallery-3-users
---
You received this message because you are subscribed to the Google Groups "Gallery 3 Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gallery-3-use...@googlegroups.com.

Adrian London

unread,
Mar 18, 2024, 7:07:28 AM3/18/24
to Gallery 3 Users
Clear! 

On your second link, where it shows the full-size with the dimensions reversed, right click in your browser and select to open the image/jpg in a new tab/window.  When I do that, it looks perfect.

From that test, it would appear the rotation is working (if you go to your server and copy over the actual jpg file it should look fine on your laptop) but the autorotate module isn't updating the database with the correct dimensions.

What happens if you re-add that jpg to your gallery?  Does the new copy/duplicate look ok?

What happens if you pick one photo and rotate it from the menu (i.e. not using the autorotate module which I don't have)?

Jon Schewe

unread,
Mar 18, 2024, 8:58:55 AM3/18/24
to gallery...@googlegroups.com
For the sizing, I see that gallery is writing dimensions into the HTML. Those dimensions are flipped. If I could figure out where those are coming from and the right values, that would likely solve this.

The other solution I have is to rotate all of the files before uploading them using the jpeg tools.
--
WHEN USING AN EMAIL PROGRAM to reply to this message, click REPLY TO LIST or REPLY TO ALL so your reply goes out to everyone in the group. If you click REPLY or REPLY TO SENDER Google will *only* send your reply to the original author (not recommended).
 
To post a NEW MESSAGE to the group, send an new email to:
gallery...@googlegroups.com
 
To view or sign in to this group on the web, use this URL:
https://groups.google.com/forum/#!forum/gallery-3-users
---
You received this message because you are subscribed to the Google Groups "Gallery 3 Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gallery-3-use...@googlegroups.com.

Adrian London

unread,
Mar 18, 2024, 9:02:58 AM3/18/24
to Gallery 3 Users
Columns "width" and "height" in the "items" database table.

I guess the autorotate module has screwed them up somehow.

J.R.

unread,
Mar 18, 2024, 6:02:47 PM3/18/24
to gallery...@googlegroups.com
Jon,

You'll probably get different people with different experiences on this. I never did get the autorotate module to work well for me and just gave up and use Photoshop to rotate them before uploading to Gallery. These days almost any graphics program with rotate an image.

-- J.R.

Jon Schewe

unread,
Mar 18, 2024, 8:43:23 PM3/18/24
to gallery...@googlegroups.com
J.R.

I understand that there are lots of programs that can handle the rotations. I even have a script that I can run on files before I upload. However I have some users of my gallery that are not that technically capable. The information is inside the image, so it's really nice that the gallery software can use it and display the image properly, when it works. 

Jon

Jon Schewe

unread,
Mar 18, 2024, 8:44:26 PM3/18/24
to gallery...@googlegroups.com
I'm guessing that autorotate is not using the right values in the right places. I haven't spent enough time in the module to understand where it gets those values from.

On Mon, 2024-03-18 at 06:02 -0700, Adrian London wrote:
Columns "width" and "height" in the "items" database table.

I guess the autorotate module has screwed them up somehow.

--
WHEN USING AN EMAIL PROGRAM to reply to this message, click REPLY TO LIST or REPLY TO ALL so your reply goes out to everyone in the group. If you click REPLY or REPLY TO SENDER Google will *only* send your reply to the original author (not recommended).
 
To post a NEW MESSAGE to the group, send an new email to:
gallery...@googlegroups.com
 
To view or sign in to this group on the web, use this URL:
https://groups.google.com/forum/#!forum/gallery-3-users
---
You received this message because you are subscribed to the Google Groups "Gallery 3 Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gallery-3-use...@googlegroups.com.

Adrian London

unread,
Mar 19, 2024, 6:45:43 AM3/19/24
to Gallery 3 Users
This is interesting.  All my photos show the right way up even though I don't have the "autorotate" module.

So I did some checking ... I always export my photos (from Apple Photos on my Mac) in jpeg format.   This exports the photos rotated correctly (based on EXIF) and then resets the EXIF Orientation field to "0" aka "Horizontal (normal)".  However, if I export the originals in ".heic" format then the EXIF field shows the original values.

Anyway ...

I've just had a quick look online at the autorotate code. It's calling G3's imagerotate function.  Did you make the code edit I suggested a few posts ago?

Jon Schewe

unread,
Mar 19, 2024, 7:32:11 AM3/19/24
to gallery...@googlegroups.com
Adrian,

Thank you for reminding me of that suggestion. I made the change, however it didn't have any effect on uploaded photos.
I tried disabling the autorotate module and that didn't have any effect.

I was looking at the modules page and saw this note "You must do 'composer install' to make this module work.". I'm not sure what that means and I don't remember using it before, but perhaps I'm missing something with the latest version of Gallery?

I would like the autorotate to work for my non-tech savy users. 

Jon
--
WHEN USING AN EMAIL PROGRAM to reply to this message, click REPLY TO LIST or REPLY TO ALL so your reply goes out to everyone in the group. If you click REPLY or REPLY TO SENDER Google will *only* send your reply to the original author (not recommended).
 
To post a NEW MESSAGE to the group, send an new email to:
gallery...@googlegroups.com
 
To view or sign in to this group on the web, use this URL:
https://groups.google.com/forum/#!forum/gallery-3-users
---
You received this message because you are subscribed to the Google Groups "Gallery 3 Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gallery-3-use...@googlegroups.com.

Adrian London

unread,
Mar 19, 2024, 8:46:39 AM3/19/24
to gallery...@googlegroups.com
So you made the code edit, uploaded a new photo, and the autorotate failed to work properly?

That’s a shame. Does it work if you disable that module and instead (just as a test) pick one new photo and do a rotation from the menu when looking at that photo? I only ask, cos that works for me.

I’ve no idea what “composer install” is either! As far as I know, no one has made any updates in years to the module pages on that old website, so I doubt it’s anything to do with the new gallery version. I would hope you get something in the logs when it fails, but from what you’ve written, it looks like the autorotate module thinks it’s doing a good job :)

Adrian.


Jon Schewe

unread,
Mar 19, 2024, 10:15:53 AM3/19/24
to gallery...@googlegroups.com
Correct, uploading a new photo doesn't rotate with the code change, nor does it rotate without the code change. Given where the code change is, I didn't expect it to fix the autorotate module.
Yes, I can rotate a photo using the menus, that does work for me.

Adrian London

unread,
Mar 19, 2024, 10:34:31 AM3/19/24
to gallery...@googlegroups.com
The autorotate module runs this: "gallery_graphics::rotate” which I thought would call the routine I had to edit, but maybe it doesn't. Until I made that edit, the rotate from the menu failed.

The module also seems to have its own EXIF stuff in “lib/pel” which might be used to write the EXIF information back to the image after it’s done the rotation. I didn’t know that was possible, as I’ve been writing info to the IPTC tags on the assumption that, without exiftool, it wasn’t possible to write EXIF information. That’s kind of interesting! Or maybe that’s why it doesn’t work :)

I guess one fix could be for the autorotate module to call the same routine as the menu option does, but I don’t know how easy that would be. I might have a play.

At least your users can now rotate the images themselves, although it’s obviously a manual process.

Adrian.




Adrian London

unread,
Mar 19, 2024, 11:08:30 AM3/19/24
to Gallery 3 Users
Oh I've just done some testing.

The rotate option from the menu, when using GD (and not imagemagick - I have no access to that) strips all the EXIF info from the photo.  On the positive side, that removes the Orientation field so that browsers etc don't keep trying to rotate the already-rotated image, but on the negative side it removes all the EXIF info!  And I like EXIF info.

A quick google tells me that this is exactly what the lib/pel stuff is trying to do - manipulate the EXIF.  So, the autorotate module must (a) extract EXIF and process the Orientation field, (b) rotate the image as required which actually creates a new image and then (c) write the EXIF info back.  Maybe that part is failing.

I've learnt not to use the rotation option(s) in Gallery3 if I want to keep my EXIF info, or I'll have to see what I can do with then lib/pel stuff.  That looks complex.  Too complex for me right now :)

Adrian.

Adrian London

unread,
Mar 19, 2024, 3:46:34 PM3/19/24
to Gallery 3 Users
Jon, do you care about EXIF information?

If not, and hence you don't mind that it gets removed when GD rotates an image, then I've knocked up a simple auto-rotate module.  Please thoroughly test it before letting it loose on real people :).

It works in my environment.  You can de-activate the autorotate module and try mine (which I've called exifrotate just to stop a clash of names).

Adrian.




exifrotate.zip

Jon Schewe

unread,
Mar 29, 2024, 12:19:35 AM3/29/24
to gallery...@googlegroups.com
Adrian,

I spent some time this morning looking at your code and the autorotate code. I notice that the autorotate code uses tempnam to get the temporary filename and makes sure to unlink the file. I notice that you are using system::temp_filename and do no unlink the file. I'm not a php developer and haven't been able to find documentation on system::temp_filename. Is there a particular reason this is chosen rather than using tempnam? Also does that system function automatically remove the temporary file or will your code leave temp files around?

I would like to keep the EXIF data if possible. Doing some digging into the files created, it appears that the large original image doesn't get modified. I downloaded the file after upload and the exif data is still there. This is both with and without the built-in autorotate module. I haven't tried yours yet.

Jon
--
WHEN USING AN EMAIL PROGRAM to reply to this message, click REPLY TO LIST or REPLY TO ALL so your reply goes out to everyone in the group. If you click REPLY or REPLY TO SENDER Google will *only* send your reply to the original author (not recommended).
 
To post a NEW MESSAGE to the group, send an new email to:
gallery...@googlegroups.com
 
To view or sign in to this group on the web, use this URL:
https://groups.google.com/forum/#!forum/gallery-3-users
---
You received this message because you are subscribed to the Google Groups "Gallery 3 Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gallery-3-use...@googlegroups.com.

Lord Beowulf

unread,
Mar 29, 2024, 12:32:33 AM3/29/24
to Gallery 3 Users

If you look through my previous posts, this sounds like what I reported about a year ago.  My problem is with portrait photos from my phone, which end up squashed.  Watching the full-sized image load from my slow website, it's apparent that the image is still rastered in landscape mode and just the EXIF information tells the browser to rotate it.  That works fine, but the problem is that Gallery 3 has the dimensions flipped in the database, so the HTML is telling the browser to squash it on the page.  I wrote my own simple PHP function to flip the coordinates on the three sets of variables that cause this behavior and it works fine.   Bit of a kluge, but it works.  Note that if I upload landscape photos from the same phone using Lightroom, it appears to work fine.  Of course Lightroom is probably re-rastering the images to be horizontal in portrait mode.

Beo

Adrian London

unread,
Apr 17, 2024, 3:07:12 PM4/17/24
to gallery...@googlegroups.com
Sorry for the delay; I've been travelling.

I simply used the same code that G3 uses.

Have a look at modules/gallery/helpers/system.php for the “temp_filename" function, and how it’s used in modules/gallery/helpers/gallery_graphics.php.  As “temp_filename” is a G3 function, googling for it won’t find anything.

The temp file is removed.

I’ve never programmed in PHP; I just go through existing code, work out what it’s doing, and copy/modify it to do what I want.

Adrian.
Reply all
Reply to author
Forward
0 new messages