Lossless JPEG rotation
December 9, 2010 1 Comment
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