Web Connection
Rotate and EXIF Orientation
Gravatar is a globally recognized avatar based on your email address. Rotate and EXIF Orientation
  Rod
  All
  Mar 7, 2020 @ 02:09pm

Hello Rick et al,

I have a WWC web/VFP app that uploads iPhone/iPad photos to my IIS server, via plUpload. After some investigation, it appears my iPhone X sets the EXIF orientation to "Normal" when you use the phone/camera in landscape position, and "Rotate 270 degrees" when you shoot portrait.

Once uploaded to my Windows IIS server, on a PC or Mac (Safari) browser the Landscape shot is heads up, but the Portrait shot appears rotated 270 degrees, which makes sense. However looking at the website images on the iPhone or an iPad (Safari), the orientation is heads up on both images. This is really confusing stuff. So the iPhone seems to be adjusting the orientation based on the EXIF to make them always heads up, but the PC/Mac browser, or IIS, is not.

Most of my users tend to use the camera in Portait, so this is a big issue.

On the website, I give my users the option to rotate the photo using Rick's RotateImage function, which as I understand it uses GDI+, which I don't know much about, or even how to find it on my server to see what version it might be. However while RotateImage (GDI+) rotates the image nicely, it does not change the EXIF. So now the Portrait shot looks heads up on the PC/Mac, but going back to the iPhone/iPad, it's tipped over to the right 90 degrees.

So I'm wondering if anyone else out there has dealt with this, or knows if there's a way to update the EXIF when you rotate the image. I've played around with VFP in the past reading the JPG file at a low level using FREAD(), but not sure trying to read and write JPGs is such a good idea. Ideally I'd like to rotate it if necessary and set the EXIF to normal when its uploaded.

Thanks, Rod

Gravatar is a globally recognized avatar based on your email address. re: Rotate and EXIF Orientation
  Rick Strahl
  Rod
  Mar 7, 2020 @ 05:22pm

I think the way to do this is to strip all the extra EXIF data from the image.

wwDotnetBridge has a static ImageUtils() class that can be used for this:

Something like this (off the top of my head):

loBridge = GetWwDotnetBridge();
loBridge.InvokeStaticMethod("Westwind.WebConnection.ImageUtils","StripJpgExifData",lcImgFile,90);

Another thing you can and probably should do anyway is use some sort of image cleanup tool. I use Pingo (and Pinga which is a GUI front end) here on the message board and on my blog to pack all incoming images after my code resizes very large ones. I believe Pingo (which is a command line tool) also strips EXIF data.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Rotate and EXIF Orientation
  Rod
  Rick Strahl
  Mar 8, 2020 @ 04:52am

Great!!! That solves the issue between the browsers and iPhone orientation. Thank you so much! I just inserted it in the onUploadComplete function just before I move the image out.

Now, I'm wondering if this wonderful class has a way to read the EXIF first so I can tell if the photo is coming in rotated. Then I could use RotateImage to set it upright before I move it as well.

Gravatar is a globally recognized avatar based on your email address. re: Rotate and EXIF Orientation
  Rick Strahl
  Rod
  Mar 8, 2020 @ 04:46pm

No my helper doesn't access the EXIF data. But I'm sure you can find code or a .NET library that does that you can use with wwDotnetBridge.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Rotate and EXIF Orientation
  Rod
  Rick Strahl
  Mar 8, 2020 @ 04:59pm

I found this information about getting EXIF properties in vb.Net. I will see if my associate can figure out how to put it to use with your class or may come back to you for services.

http://www.vb-helper.com/howto_net_read_exif_orientation.html
© 1996-2020