Lossless JPEG rotation

Since I’ve moved and now I’m living in place in which I take a lot of pictures, I’ve been using a lot the portrait type of photo. So, most of times I need to rotate the images 90 degrees. With Gimp you can rotate, but there is a quality loss in the image. Jhead was not an option also because my digital camera save the image with Orientation flag equals 1, no matter how I took the photo. So, I did a Python script to rotate the images using Jpegtran — it is part of libjpeg-progs package.

import os, glob
path = '.'for infile in glob.glob(os.path.join(path, '*.JPG')):
os.system("jpegtran -rotate 90 %s > temp.JPG; rm %s; mv temp.JPG %s" % (infile, infile, infile))
print "Rotating %s ..." % infile

One Response to Lossless JPEG rotation

  1. Rotate JPEG says:

    Jpegtran has an argument called -outfile. You can overwrite the original JPEGs without a temporary file using this. For example jpegtran -rotate 90 -outfile example.jpg example.jpg will work. I have tested it myself. Also I recommend that you pass -progressive and -optimize arguments to get smaller JPEG files.

    Also if you are on the go and do not have access to jpegtran, check out my website: https://rotatejpg.com/ which lets you losslessly rotate JPEGs in your browser using Javascript.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: