View Full Version : How do I disable images from auto-rotating? This problem is on this forum too.
larrydude
09-29-2014, 04:53 PM
Some of my forum members complain that their images look fine everywhere but once they upload to the forum then they rotate.
I tested this with one of their images and this happens. In my searches it appears that ImageMagick may be rotating these images based on exif info.
How can I disable whatever is auto-rotating my member's images?
Thanks in advance for assistance.
ForceHSS
09-29-2014, 08:19 PM
Do you have a plugin that has anything to do with images
larrydude
09-29-2014, 08:39 PM
No additional plugins related to images are used at all. The forum uses ImageMagick on 4.22 pl1.
thanks.
ozzy47
09-29-2014, 08:43 PM
What do you mean by rotating?
larrydude
09-29-2014, 09:02 PM
Certain images apparently has EXIF info in them that when uploaded to the forum they are auto-rotated 90 degrees counter-clockwise.
These appear to be images taken on an Iphone in landscape mode (at least what I have tested) where the image looks perfect on a computer. It can upload to social media sites without problem.
But when the member uploads, it goes from looking correctly to rotate 90 degrees counter-clockwise
I have uploaded the original image and a screenshot of what happens when the members/I upload. /// This forum does the SAME thing! The original image looks perfect on the computer before uploading.
Keep in mind that most uploads are fine. It is only certain images....
larrydude
09-29-2014, 09:03 PM
I just noticed the thumbnail on THIS forum rotates it just like on my forum. Then when you click on it you can see the way it should be. Notice that this forum only rotated one of the two.
Certain images apparently has EXIF info in them that when uploaded to the forum they are auto-rotated 90 degrees counter-clockwise.
These appear to be images taken on an Iphone in landscape mode (at least what I have tested) where the image looks perfect on a computer. It can upload to social media sites without problem.
But when the member uploads, it goes from looking correctly to rotate 90 degrees counter-clockwise
I have uploaded the original image and a screenshot of what happens when the members/I upload. /// This forum does the SAME thing! The original image looks perfect on the computer before uploading.
Keep in mind that most uploads are fine. It is only certain images....
--------------- Added 1412097558 at 1412097558 ---------------
--------------- Added 1412097660 at 1412097660 ---------------
Does everyone see the problem here? Is this a bug in Vbulletin since it is happening even here? The thumbnail is shown in one orientation, then the actual image is shown correctly if you click on the thumbnail.
Bill Stuntz
02-22-2015, 02:05 AM
Actually, I think you're looking at the problem BACKWARDS. The exif data says Landscape even for Portrait photos, with an orientation tag telling the computer to rotate it to portrait when it's displayed. ImageMagick seems to ignore that orientation tag, and the OTHER programs obey it. I found this, but haven't figured out how to actually DO it in vB. If anyone can help, I'd appreciate it. I think it's just an option that needs to be specified as ImageMagick is executed to process the photo.
Digital Photo Orientation
I have been told that Photoshop will automatically rotate digital images based on the EXIF 'Orientation' setting, IM will also do this by including a "-auto-orient" operator, after reading in the image.
--------------- Added 1424646395 at 1424646395 ---------------
Here's a link demonstrating OUR problem:
http://mb.nawcc.org/showthread.php?122061&p=936938#post936938
larrydude
02-22-2015, 09:49 PM
This is acknowledged as a bug in the vbulletin.com bug tracking system. People have to vote it up before they will consider fixing it. I do not recall the name of the problem. This is a problem that most forum owners do not know is a problem. I believe it is a problem for all vbulletin forums (at least ver. 4x.x).
This is more of an issue on forums that have images that originated from mobile devices. To my knowledge there is no fix.
Actually, I think you're looking at the problem BACKWARDS. The exif data says Landscape even for Portrait photos, with an orientation tag telling the computer to rotate it to portrait when it's displayed. ImageMagick seems to ignore that orientation tag, and the OTHER programs obey it. I found this, but haven't figured out how to actually DO it in vB. If anyone can help, I'd appreciate it. I think it's just an option that needs to be specified as ImageMagick is executed to process the photo.
--------------- Added 1424646395 at 1424646395 ---------------
Here's a link demonstrating OUR problem:
http://mb.nawcc.org/showthread.php?122061&p=936938#post936938
Bill Stuntz
02-22-2015, 09:58 PM
Yeah, I know. And our site is VERY dependent on images. It's a PITA to have to manually correct iPhone & pro grade camera photos.
That "-auto-orient" trick might work, but I don't know enough to actually try it. And the upside-down photos when they rotate the camera the "wrong" way are especially annoying.
Hmm...I downloaded the example that was posted above, and I notice that the orientation varies a lot. I'm working on a Windows system, and I find that the image looks right in browsers and in an image processing program called Gimp (which actually offered to rotate it when I opened it), but it looks sideways in the other Windows image viewers that I tried. My understanding of the problem is that Apple decided to leave images un-rotated and put orientation info in the EXIF data, but not every program respects that.
So it seems like there would be two ways to handle it: either rotate the resized images so that they're right side up, or else transfer the EXIF data to the resized images, so at least they'll look the same as the original.
Bill, did you try adding the -auto-orient to the code like I mentioned on vbulletin.com? I think it might only work for thumbnails, but at least we'd know if it worked at all. I'll try it myself but I don't have ImageMagick set up yet, and I'm not sure I'll be able to get it to work on my test system I have installed on my Windows machine.
Actually, it does work for thumbnails, but the added line has to go in a different place than I thought. I added it near the beginning. Here's my code fragment, from includes/class_image.php, around line 760 (I added the line in red):
if ($thumbnail)
{
// Only specify scene 1 if this is a PSD or a PDF -- allows animated gifs to be resized..
$execute .= (in_array($imageinfo[2], array('PDF', 'PSD'))) ? " \"{$filename}\"[0] " : " \"$filename\"";
}
else
{
$execute .= " \"$filename\"";
}
$execute .= ' -auto-orient ';
if ($imageinfo['scenes'] > 1 AND version_compare($this->version, '6.2.6', '>='))
{
$execute .= ' -coalesce ';
}
So, that's at least a small improvement since the thumbnails will look right.
Oh, I added that line to the code then went to the admincp, Maintenance > General Update Tools > Rebuild Attachment Thumbnails. But that will probably take a long time (it took me a minute and I only have a few test attachments), so you'd probably want to try it first by attaching a new image, or maybe don't run the rebuild but just let it work for new images, if you've been fixing the existing ones.
Bill Stuntz
02-22-2015, 10:56 PM
It works differently in different browsers, too. FF & Chrome behave differently than IE & Safari. At least, I THINK I have the browsers right - it's been a while since I tested them all when people were saying that the different size views displayed differently. In some browsers, the thumbnails & magnified views display in different orientations. In others, they're all sideways.
With multiple execute's, can the FIRST one that executes correct the orientation, and later ones do the resize & thumbnail creation as more passes through IM are made for the other views? Or does only 1 execute happen? With all those IF's I'm not sure yet whether more than one execute actually occurs before the process completes.
I'll have to look at things more closely when I get a chance. As I mentioned above I got the thumbnails to orient themselves, but the larger image that pops up still isn't right and I'm not sure why. Also, when you attach an image then edit the post you can double click and bring up a popup that lets you change the size, but once I did that nothing looked right any more, even when I went back to thumbnail.
Bill Stuntz
02-23-2015, 12:02 AM
We've been correcting the images as we find them, so the rebuild probably isn't necessary for us. And I've noticed that IM seems to strip out the orientation & camera info tags when it resizes. So if it's resized first, there's no exif orientation tag to trigger the rotation. The only way I was able to track down the problem was by examining the few photos that were taken at low enough resolution that IM hadn't resized them as they were uploaded/stored on the MB. I used JPEGsnoop to see/analyze several of the weird photos. I've had a few users email me the original (untouched by IM) photos for comparison. The image quality ON SCREEN after resizing is ALMOST as good as the original. It's good enough to see most of the essential details, but not good enough for true archival/research work. If you'll give me your email in a PM, I'll send you a few if you want.
IMHO, the proper order of operations is: Rotate the full size photo if it contains an exif orientation tag, THEN generate the other views, with the largest view resized down to 1600W for storage after rotation to make the resulting image as large as reasonable for our available storage & bandwidth. Normally, 200x200 thumbnails are visible in the posts, and users can get progressively larger views by clicking on the visible photos.
Zachery
02-23-2015, 12:33 AM
The issue is not the forum software, the issue are the phones taking the pictures and only saving orientation data instead of actually rotating the picture correctly in the first place.
While I think it's worthwile to fix the problem in vBulletin, its unlikely to get backported to vBulletin 4.
kh99, if the image isn't over any limits, we don't do any modifications to it. I'm guessing that you're going to need to write something to check if the image has the orientation metadata and then do something based on that to fix the image when we do image checking from the original upload.
Bill Stuntz
02-23-2015, 02:02 AM
I agree, the problem is only with the iPhone, Canon, Nikon and maybe a few other cameras. But it will probably get worse as cameras & cell phones improve and prices go down.
There are a LOT of iPhones out there - and they're not going to go away. I'm not sure, but ios8 may have fixed the problem - but that's just speculation. I haven't seen enough photos that I'm SURE are ios8. That info gets stripped out of the jpg's in the resize, and I never see the original photos to be sure. And I don't have an iPhone to test.
I'm guessing that you're going to need to write something to check if the image has the orientation metadata and then do something based on that to fix the image when we do image checking from the original upload.
Please don't take this as an insult, but if I'm not mistaken, adding that "-auto-orient" early in the process might be an easy way to fix the problem for everyone - IF it works. And I'm not a good enough programmer anymore to find out. I haven't done any serious programming since CP/M days, when I wrote a text editor in 8080 assembler because I hated edlin so much, and couldn't afford to buy a screen oriented editor instead of the line oriented one that was built into CP/M.
Do the rotation first if the orientation metadata is there, and THEN figure out whether it needs to be resized, etc. and do the rest of the processing. I've seen quite a few complaints about this problem on our MB and elsewhere, and I think it occurs in 5, too. I have no idea how they do it, but a lot of other web sites DO automatically orient the photos properly, so it's obviously NOT impossible.
Do the rotation first if the orientation metadata is there, and THEN figure out whether it needs to be resized, etc. and do the rest of the processing. I've seen quite a few complaints about this problem on our MB and elsewhere, and I think it occurs in 5, too. I have no idea how they do it, but a lot of other web sites DO automatically orient the photos properly, so it's obviously NOT impossible.
Yeah, I think that's going to work. With the -auto-orient that I've got in there now, the thumbnail works and the original size works, but the intermediate "lightbox" image doesn't for some reason I don't understand. But what I did was took the sample image and ran the command line IM program on it with only the -auto-orient option, and that image works completely. The only problem is that I don't think there's anywhere to just add the -auto-orient, so it's like Zachery said, we need to find the point just after it's been uploaded and add a call to do the conversion. That shouldn't be too hard, I think it's uploaded to a temp file before anything's done to it.
Bill Stuntz
02-23-2015, 05:52 AM
I hope my insights have you pointed in the right direction.
I've noticed that some browsers ALWAYS display them wrong, and others seem to get it right for some magnifications. Maybe lightbox is still working with the un-rotated image after it's actually been rotated into the new file? Or does its thing too soon, before it's rotated - and the thumbnail is generated after rotation? There are so many IF's in there that I'm not sure. Maybe more than 1 -auto-orient is needed?
It sure would be nice if there's an easy fix for ALL of us, even if it only works for future photos. :) I can live with that. It will save me a lot of trouble.
Zachery
02-23-2015, 10:48 AM
My point was to help get kh99 on the right track, and explain the problem.
kh99, there is a check in the IM processing part of the class_image to check the filetype, maybe you can run some code there.
Mobile devices read and recognize the metadata, browsers don't care. Maybe they should, but they don't.
Well, I wanted to explore Bill's idea of adding -auto-orient, and since it turns out that fetch_thumbnail does all the resizing, and it's easy to add the option there, then I thought that might work. But as I said, the lightbox image doesn't work and I'm not sure why. But rather than track that down, I think it's better to try what Bill said and rotate it if necessary before doing anything else. A couple years ago I was working on a mod that read and displayed EXIF data from upload files that had it, so I know there's a hook where you can work on the uploaded file before anything else is done to it. I've just been looking in to that and I believe newattachment_start will work. So it's just a matter of writing the code to exec the IM programs using the temp file name, convert it to a new temp file name, then replace the name in $_FILE. It would be nice to use the existing code in the IM class, but that would mean modifying the file.
In any case I think I'm pretty much there and it's just down to the details of implementing it.
Bill Stuntz
02-23-2015, 03:04 PM
My point was to help get kh99 on the right track, and explain the problem.
kh99, there is a check in the IM processing part of the class_image to check the filetype, maybe you can run some code there.
Mobile devices read and recognize the metadata, browsers don't care. Maybe they should, but they don't.
:) Thanks for your help - both Zachery and kh99! :D
The phrases I bolded in that quote and my comment may be the most important ones in this whole thread, emphasizing the level of attention I think this problem deserves. It's not a trivial problem for our moderators and users. I hadn't thought to phrase it Zachery's way. I'm trying to help get the problem fixed, too - for everyone. It's been ignored for way too long. Only a few cameras/photos cause the problem - mostly the ubiquitous iPhone. But everyone uses a browser to view our photo-intensive 100K+ thread educational MB. Approximately 130 registered users and 1400 guests are online as I'm typing this. Most of the threads they're browsing contain photos. And they need to stand on their heads to view a few of the photos in the correct orientation. :( If they're using a phone or tablet, turning IT upside down doesn't help - the orientation sensor causes the photos stay upside-down/sideways, anyway!
OK, Bill, larrydude, or anyone else who wants to try it, I'm attaching a product, if you want to test it for me you can import it in the product manager, then go to the options and set Enable to Yes.
I've tested it only with the one image that larrydude posted, but the only issue I can really see is maybe large files will cause memory or time issues. In any case, if you do test it let me know how it goes, and I'll release it so other people can use it if they want.
(Removed attachment - see updated version below)
Bill Stuntz
02-24-2015, 05:23 PM
I plan on testing, but as I said, I'm new at this stuff. So it might take me a while to figure it out. I can send you a 6MB original "sideways" photo, excerpts from the exif data below. This is typical of the photos that give us trouble, but maybe a little large. We resize them to 1600wide, and they store at <250K or so in our database. Please PM me or something if I can send it to you.
[Model ] = "Canon EOS REBEL T2i"
[Orientation] = 8 = Row 0: left, Col 0: bottom
Image Size = 5184 x 3456
Raw Image Orientation = Landscape
P.S. It's that Orientation = 8 and the fact that it SAYS landscape instead of portrait that's driving me nuts.
OK, I got your sample images and tried them, and they seem to work OK. I'm working on an old, slow PC and the large one took maybe 30 seconds to a minute to rotate, so I'd imagine on a modern server it wouldn't be that noticable. I'm attaching a new version here, so let me know how it goes.
(Removed attachment - see below)
Bill Stuntz
02-24-2015, 07:46 PM
I just tested the in our off-line test copy of 4.2.2 using FF.
enabled: thumb sideways, expanded upright (IMG_0014)
disabled: all sideways
6MB: upload failed (undefined) enabled or disabled - may be a problem in test MB, uploads OK in live MB.
Haven't tried other browsers yet.
OOPS!!! I lied - thumb & lightbox sideways, full size upright in both cases!
I'm not sure I follow all that, but it sounds like you're saying that it's not working for you? I guess the full size will be upright because the browser knows how to display it.
You do have IM configured on your test site, right? The browser shouldn't matter if it's working, the thumb, lightbox, and full size should look the same. I guess I'll have to make up a version that has some kind of debugging output.
Bill Stuntz
02-24-2015, 08:00 PM
Maybe I did something wrong installing? As I said, I'm new at this, and the behavior seems unchanged. just for the heck of it I'm going to attach that image here.
No, if you got it installed so the options are showing up, that's all that you should need to do. Well, as long as you have ImageMagick set up in the Image Options, but I'm assuming that you do.
I'll add some messages so I can figure out what's going on. There are a lot of things that can cause the mod to give up.
Bill Stuntz
02-24-2015, 08:08 PM
I'm going to PM you a link to those posts in our test copy of the MB.
Bill Stuntz
02-25-2015, 01:29 AM
I'm starting to wonder whether we might be barking up the wrong tree, based on these - especially the "scaled to" in the one named "14-full size upright"
How/why did the system decide to scale 640x480 image to 480x640?
Hmm...I'm not sure what that means. Anyway, I have a new version. It turns out that this mod works on vb3 so I was able to try it on our (linux) server, and there was a problem, which I hope has been fixed now, so, when you get a chance try this version.
Bill Stuntz
02-25-2015, 03:39 PM
That last post's captures were right-click "View Image Info" in FF.
These 3 screen captures are "Inspect Element" in FF, Chrome, & IE after installing new version.
IE, all sideways, FF & Chrome thumb&lightbox sideways + full upright.
Is that the results using the latest? Or are you explaining your previous post?
Bill Stuntz
02-25-2015, 04:07 PM
Both. I wonder if there might be a cache problem and the new install hasn't "taken" yet???
Oh, I see now. I don't know what confused me before. Anyway, looks like that means it's still not working for you. I started out his morning meaning to put in debugging messages, but when I found that problem I thought maybe we'd get lucky. Hopefully we'll get this working and it will fix the other issue.
Both. I wonder if there might be a cache problem and the new install hasn't "taken" yet???
Are you testing with new posts, uploading the attachments (even if they're the same images you used before)? If you're uploaidng them then it should happen right away, unless it's failing for some reason.
Would you happen to know which version of IM you have? On our server I found identify and convert installed in /usr/bin, but it turned out they didn't know about the -auto-orient option. I don't know which version they are but I assume it's old.
Bill Stuntz
02-25-2015, 04:53 PM
I'm re-uploading the original photo each time, and then viewing the new post in various browsers. It's small, and I know it displays wrong every time in every browser.
CP under "Image Settings" says ImageMagick 6, but I suspect that text is built into vB. As I said, I'm new at this. How can I find out the REAL version of IM? When I download the stored image from the MB, it comes back identical to the copy I uploaded, probably because IM didn't have to resize it. Zachery said the original jpg would be stored if it's already small enough, so that didn't surprise me.
I think if you can run one of the programs from the command line (with no arguments) it prints the version at the top. But I just did that on our server and found that it was version 6.2.something and it didn't know what -auto-orient was, so I guess it was something added recently. So I'm guessing that's the problem you're having. But maybe what I can do instead is read the orientation and give it an explict rotate command, because I'm pretty sure that's all that's happening anyway.
Anyway, if you do have the ability to run from a command line, you can do something like convert -auto-orient img.jpg img2.jpg and see if it complains about the -auto-orient. I'm not sure if the 'img.jpg' file really has to exist, but if it does you can probably use 'touch' to create it because you don't care about the result, only about whether or not it recognizes the option.
Bill Stuntz
02-25-2015, 05:26 PM
I don't have access to the command line, just the MB. I've asked our head admin about the version number.
I could be wrong about that anyway. I looked at the IM change log and I see mention of -auto-orient from version 6.3 back in 2007, so I guess we have a very old version, but you may not.
Anyway, I'll go back to the debugging idea.
I guess we should be PMing instead of bothering everyone with this. :)
Bill Stuntz
02-25-2015, 05:44 PM
Based on this, I didn't want to do that. But will do so now. I agree, pretty disruptive here.
Please don't PM me - post your questions in the appropriate forum.
Please don't PM me to ask me to read your thread.
Or maybe we should move it over to the programming forum?
Based on this, I didn't want to do that. But will do so now. I agree, pretty disruptive here.
Yeah, I maybe should remove that. I added that because a few years ago when there was more activity here I'd get a few of those a week at least, people wanting me to solve their problem via PM instead of the forum, or asking me to read their thread. I just want to read the forum and answer the ones I feel like answering.
Anyway, it's my fault for posting so much here. I would have stuck with PM except you can't have attachments.
Just happened upon this thread again so I thought I'd post that we did actually get this working eventually, and it's available here: https://vborg.vbsupport.ru/showthread.php?t=318291 . It requires ImageMagick to work, but my understanding is that even some shared hosts have that installed, you just need to figure out the path to the executables.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.