by ʇolɐǝz ǝɥʇ qoq

Submit your Photo
Hall of Fame

Please participate in Meta
and help us grow.

Photography Stack Exchange is a question and answer site for professional, enthusiast and amateur photographers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can I rotate lossily compressed photos that I view in Windows Photo Viewer without worrying about losing even more information to compression?

share|improve this question
Note that--as far as I know--a 90 degree rotation (and 180, 270) is lossless in and of itself because it is a swap of x and y coordinates (other angles require interpolation). So any lossyness attributed to the transform is from the recompression. You can avoid this recomputation by saving the transformed image in a lossless format, but that is clearly not part of your question, so I won't suggest it – horatio May 24 '11 at 18:32
@horatio, the multiples of 90 degrees are a special case for JPG compression, where it is technically possible to rotate the image without a compression cycle by "simply" rearranging the compressed data. It does involve removing and applying a layer of lossless compression, so the file size might change, but no lossy operations are required. – RBerteig May 24 '11 at 18:54
I think I understand you, but my point is that jpeg is a disk storage format and does not have any bearing on the quality of the transforms themselves. That is to say, though one often speaks of working with jpegs etc, while the file is displayed on screen and manipulated, it is not a jpeg. – horatio May 24 '11 at 19:59
Man I have ALWAYS wanted to know the answer to this question. IMO they SHOULD be. But most likely due to the JPEG standard... I don't think it is technically possible to make this operation lossless. – Trevor Boyd Smith May 24 '11 at 20:46
Google Picasa image viewer IS lossless. but it cheats. it doesn't rotate the image. it just marks down in meta data "display this image rotated". – Trevor Boyd Smith May 24 '11 at 20:46
up vote 50 down vote accepted

If the dimensions of the image are multiples of 8 (or 16 if chroma subsampling is used) then the rotations are lossless. Otherwise it is not possible to rotate the image without recomputing the blocks i.e. recompressing the image, which is lossy.

The reason for this is that jpeg images are broken up into a series of 8x8 or 16x16 blocks which are compressed individually. Incomplete blocks are only allowed on the right edge and bottom edge. Thus is your image is not an exact multiple of 8/16 it will contain incomplete blocks, which will end up on the wrong edge after rotation.

I verified the above assertion using the version of Windows Photo Viewer that ships with Windows 7. I used two images of colour noise. One image was 256x256 i.e. both sizes multiples of 8. The other image was the same but cropped to 253x253 i.e. neither size was a multiple of 8. Here are the images:



I then performed four anti-clockwise rotations, closing photo viewer after each rotation to ensure the image was saved in it's rotated state.



There's no need to perform a subtraction to see the difference with the 253 pixel image, it's noticeably darker and muddier!

A diff on the other image looks like this:

i.e. the images are identical, the rotations were lossless.

share|improve this answer
Do you know for sure that this particular software does a lossless transform in the case where it's possible? I know that, for example, ImageMagick does not. – mattdm May 24 '11 at 12:33
I know that in the past when I've done rotations it has warned me that the rotation would be lossy, which implies that in cases where the warning wasn't displayed the transformation was lossless, but I didn't check. Nor do I remember what version of WPV I was using, not precluding the possibility that MS changed the codebase, so no I can't be sure. – Matt Grum May 24 '11 at 13:55
@MattGrum, you are answering the question "is it possible to do a lossless rotation on jpeg file"... which is NOT the question. the question is "can xyz program do a lossless rotation". I strongly suggest editing your answer to answer the right question (and suggest making it more concise...). – Trevor Boyd Smith May 24 '11 at 20:50
@TrevorBoydSmith The answer to "can xyz program do a lossless rotation" is dependent on "is it possible to do a lossless rotation on jpeg file". Honestly, answering the latter question is a much better answer than just the former. – Arda Xi May 24 '11 at 21:41
@Trevor I've now answered both questions :-) – Matt Grum May 25 '11 at 17:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.