As JPG is a lossy compression, every re-encoding losses quality. Thus, 90/180/270 degree rotation is a lossy operation as well. Is it possible to change orientation of JPG photo by changing some of its metadata tags so that the orientation can be changed without re-encoding the photo?
Is it possible to change orientation of JPG image without rotating it (and thus losing information)?
Asked
Active
Viewed 5,494 times
1 Answers
18
JPG can be rotated using only EXIF data, so no re-encoding is necessary.
I found this tutorial on the orientation flag - JPEG Rotation and EXIF Orientation
These days, most image apps can handle this flag, many can also write it.
Exiftool is a very comprehensive multi-platform solution that can handle all exif data - see How can I modify the EXIF orientation tag of an image?
Nick Westgate
- 1,811
- 1
- 16
- 15
Tetsujin
- 47,296
- 8
- 108
- 135
-
1Thanks! I also found a [solution using ExifTool](https://photo.stackexchange.com/a/104340/6546). And I also found that IrfanView can do a lossless rotation (menu Options / JPG lossless rotation), do you know if it works via EXIF as well? :-) – Tomas Dec 04 '20 at 13:12
-
15jpeg images can be really lossless rotated by 90 degrees (see https://stackoverflow.com/questions/543402/can-a-jpeg-compressed-image-be-rotated-without-a-loss-in-quality) – xanatos Dec 04 '20 at 20:59
-
Besides, EXIF data does not rotate an image. It only provides a hint to renderers to perform their own rotation on display. Such a rotation is probably _worse_ than even a lossless "real" rotation performed ahead of time, for performance reasons. – Asteroids With Wings Dec 04 '20 at 21:35
-
2@Tomas https://photo.stackexchange.com/a/104366 _IrfanView can indeed rotate JPEG images in a lossless way, and it indeed needs the JPG_TRANSFORM plugin to do that. Luckily that plugin is already included in a normal install of IrfanView. To check you have the plugin: go to Help -> Installed PlugIns and check if JPG_TRANSFORM.DLL is in the list._ – xanatos Dec 04 '20 at 22:46
-
5Note that a lossless true rotation is only possible if the image size is a multiple of the block size in both dimensions (depending on the subsampling options used, the block size may be 8x8, 8x16, 16x8 or 16x16). – plugwash Dec 05 '20 at 01:29
-
1`Note that a lossless true rotation is only possible if the image size is a multiple of the block size in both dimensions` - Forsooth, IrfanView will give an error if you try to use the lossless-rotation function on images that have incompatible dimensions. Still, most unmodified images (straight from the camera, screenshot tool, etc.) will have compatible dimensions. – Synetech Dec 05 '20 at 15:44
-
1`jpegtran` specifically has a `-perfect` option that can be used for lossless rotation and cropping. – chrylis -cautiouslyoptimistic- Dec 05 '20 at 18:58
-
@AsteroidsWithWings Why would such a rotation (on display) be "worse"? It would be a rotation on the (already decoded) bitmap it memory, no re-encoding to create loss? – MrWhite Dec 06 '20 at 19:36
-