Got back from holidays, and after copying my photos to my Windows I see (again) that the default Windows picture viewer doesn't respect the orientation flag in the EXIF tags.
I fired mogrify from imagemagick to rotate the pixels in the photos according to the EXIF orientation, so that stupid Windows can show them correctly
> mogrify -auto-orient *.JPG
So far so good, but then I suddenly I thought, is ImageMagick rotating JPEG photos loss less? For the non initiated, JPEG compress your photos very well, but at the expense of not storing exactly the color of each pixel. If you read and store again the photo, you're doing it probably with slightly different settings, so the program that stores the photo creates a new JPEG that stores the photo with more incorrect pixels. Even worse, it tries to reproduce the bad pixels the first encoding created, so the result is worse than what you expect. After a few transformations, what used to be a "slight invisible difference" between the original and the first JPEG, becomes a big drop in quality in the last JPEG. Most people regularly rotate several times the photos, resize them, and crop them. If after each step you save the photo and reload it, you're degrading the photo.
I did a quick test to check if ImageMagick rotates lossless-ly the photos, putting the rotated photo over the original in GIMP, choosing the difference filter. If everything is pitch black then it's lossless. I got something that looked black, but looking at the histogram showed that not everything was completely black. I then switched solid black to solid white, and the you can see the result here:
Arggh, so I lost a bit of quality on all my photos from my last trip to Paris. I then tried to make something constructive out of this, looked up this issue and the ImageMagick guys recommend to use jhead & jpegtrans to do lossless rotations, crop, resizes in JPEG images. These tools don't read the pixels and try to encode them again, they know how JPEG works are thus able to do these operations lossless-ly if you don't try to modify any of the JPEG blocks in the image (of 8x8 pixels).
So I tried it, and this time I tested it before I apply it to my new photos from Switzerland:
> jhead -autorot IMG_3778.JPG
And tried to see the difference again the GIMP. This time I got a much better histogram, but still not pitch black. Again, changing solid black but white showed some noise, more or less uniformly distributed over the image. Zooming in to 1:1 I got (cropped a 200x200 part of the image):
I don't understand this time why is there any difference at all. Anybody has any clue?
P.S.: To my girlfriend, that's why I'm so slow copying & selecting the photos from our trips...