Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

It's been over a year since I released the last version of jPhotoFrame. Lately I had a few issues with some photos not rotating correctly so I decided to add an image rotation utility and release a minor update to jPhotoFrame. So version 0.3.1 is now available to download from GitHub.

The source code is of course still in the same spot - https://github.com/ikromin/jphotoframe.
I've now released verision 0.4 - please refer to this article - jPhotoFrame version 0.4 released with a whole new layout engine.

This release addresses the issue of incorrectly rotated JPEGs. This can happen when you hold your camera/phone in an unusual orientation while taking a photo. Since the orientation of the data inside the JPEG and how the image is meant to be displayed do not always match, it's possible to get some images being displayed with incorrect rotation. Most modern tools take care of this orientation mismatch for you so it's usually not noticeable. You can learn about this more here.

However, because jPhotoFrame is just using vanilla Java code to load and display JPEGs it was doing things like this sometimes...

Oops! That particular image should have been rotated by 90 degrees to the right.

Based on this and with the aid of the mediautil library I put together a small utility to recursively fix image orientation for all JPEGs in a directory. This utility scans the entire directory and all of its subdirectories, tries to load any JPEGs it finds and if the orientation needs adjustment, it rotates the image data to a standard orientation and overwrites the original file.

The output looks something like this...
Reading file - /Personal/tmp/photos/20170211_152556.jpg
EXIF data found in image
Transforming image to correct orientation
Frame, precision 8
X= 1024, Y= 768
Components 3 (/Personal/tmp/photos/20170211_152556.jpg)
Size in MCU 64x48
0x51dd8(335320) byte(s) read in 20170211_152556.jpg
Writing image to disk

The end result is correctly oriented images!

Running this utility is a matter of running the fixrotation.sh script or doing something like this...
java -Xms128m -Xmx256m -jar jphotoframe.jar -fixrotation /Personal/tmp/photos

Here the directory name is /Personal/tmp/photos. As mentioned earlier this utility will attempt to fix all JPEGs in this directory and all of its subdirectories.

I ran this on a few hundred images and it runs pretty fast and so far has worked quite well. Don't forget to look at the README and download the latest version 0.3.1 package here.


A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.