Lossless jpeg rotation just involves setting an orientation flag in the jpeg image header. Many modern cameras also set the camera orientation in the EXIF data, and most photo editing tools can auto-set the image orientation from the camera orientation. Jpeg display libraries should honour the jpeg orientation flag.You cannot just shuffle arrays because jpg files are not arrays of bytes, it is a stream that encodes clusters of data. So any rotation involves decompressing the data into a bitmap, rotating the bitmap (which is shuffling arrays) and then recompressing the image to a new jpeg.
But the data you have to compress is not the original image, it is the decompressed jpg with compression artifacts. Which then gets compressed into an image with more compression artifacts - losing more of the original data from the final rotated jpg.Si. Do you know if Photoshop does this by default? I've been using Photoshop to rotate images for a long time (among other things, of course) and it never occurred to me that I might be compressing it further with every single rotation.As far as I know, Photoshop doesn't do lossless JPEG rotation.
If you resave a JPEG as a JPEG, you will lose some data. If you save your rotated JPEG in a lossless format, you will not.To be honest, if you use fairly high quality settings for your JPEG compression, an extra pass through the algorithm is not going to be noticeable for the vast majority of photographic data (I'm not talking line drawings and the like here.) In fact, I make prints of JPEGs of JPEGs all the time (at 80% quality setting), and darned if I can tell the difference. Yes, ideally you always want to keep the highest possible quality file around.
I keep RAW files of every last thing I shoot. But I don't freak out if I need to make a print of a JPEG of a JPEG. It looks fine, unless you've compressed it to holy hell (or if it's not a typical continuous tone photographic print.). Why would lossy rotation be the default, anyway? For multiples of 90 degrees, at least, lossless rotation would just entail a straightforward shuffling of arrays, and would almost have to be simpler than any sort of lossy method.Because most programs aren't just designed to rotate, but to edit the image, and thus convert it to Bitmap first. And then, when you save, it converts that image back to JPEG.
It's only specialized JPEG rotation utilities (or commands) that actually alter the JPEG file itself. Quote:Lossless jpeg rotation just involves setting an orientation flag in the jpeg image header. Many modern cameras also set the camera orientation in the EXIF data, and most photo editing tools can auto-set the image orientation from the camera orientation. Jpeg display libraries should honour the jpeg orientation flag.Ah, this does explain a problem I (or rather, my father) have had.
When I take a picture with my camera, I orient the camera for portrait or landscape according to what better frames the picture, and they show up on my screen oriented correctly. But when I send them to my dad, he always complains about the sideways pictures.
How To Rotate A Jpeg
Given that he uses Microsoft products exclusively, and given Microsoft's attitude towards standards they didn't create, they probably just didn't implement the rotation flag.
I have some server code that is generating thumbnails when an image is uploaded. The issue is that when the image was taken and the camera/device was rotated, the thumbnails are rotated, even though the full size images themselves are displayed in the correct orientation in any image viewing software. This is only happening with jpgs.Using Preview on OSX, I can see that jpgs have orientation metadata embedded within. When I use ImageTools (Grails Plugin) to generate a thumbnail, the EXIF metadata is not in the thumbnail, which is why the thumbnails appear rotated.Via offline conversations, I have learned that while it is relatively easy to read EXIF metadata, there is no easy way to write it, which is why the data is lost when generating a jpg thumbnail.So it seems I have two options:. Use ImageMagick to generate the thumbnails. The downside is it requires installed more software on our servers.
Read the EXIF Orientation data is code and rotate the thumbnail appropriately.Does anyone know of any other options?