Does the forum support EXIF orientation tag in JPEG images? - Page 1
Forum section: electronics / general

author: magic
author_rank: Super Contributor
timestamp: August 31, 2022, 03:05:51 pm
content: Only one way to know...

author: magic
author_rank: Super Contributor
timestamp: August 31, 2022, 03:10:44 pm
content: The preview generator clearly doesn't.Moreover, the tag is stripped from the uploaded image as well, so downloaded copies appear wrong in all browsers and other software.

author: magic
author_rank: Super Contributor
timestamp: August 31, 2022, 07:45:44 pm
content: Ehm, yes, for those wondering what this is about.JPEG files may contain EXIF metadata. One item of particular interest is theExif.Image.Orientationtag, which - if present - specifies that the image should be rotated (in 90° increments) or mirrored before being shown to the user. A common source of such images are digital cameras in portrait orientation - they actually write the file in landscape orientation and then add this EXIF tag. Another source is some simple image editors and viewers, which implement "rotate left"/"rotate right" functions on JPEGs by means of altering the EXIF tag only.Needless to say, not all software honors this EXIF tag and some websites remove some or all EXIF tags from images uploaded by users, with or without correcting the orientation. The ZIP archive attached to this post contains a JPEG file which tests any software for handling of EXIF orientation. The image is encoded upside down, and then an EXIF tag is added requesting 180° rotation.Fixing orientation the easy way.Open and then save the image again with a graphics editor which encodes JPEGs in correct orientation right away, without EXIF trickery. The free image editor GIMP is one such program and I suspect even MS Paint could work, if it still exists in Windows. When loading a JPEG file, GIMP will ask whether to rotate the image in accordance with EXIF metadata, you probably want to answer "yes" to that if you are here. To write a JPEG file in GIMP, you need the "export" function rather than "save"This is an opportunity to also reduce the size of your file by scaling down to fewer pixels and/or reducing the "JPEG quality factor", if no visible deterioration occurs.Rotating JPEG images the lossless way.The decode-encode loop described above induces quality loss, which may be undesirable if the original image already suffers from high compression. Saving at a higher quality factor could reduce the additional loss, but increases file size quite needlessly.A few simple transformations including rotation can be performed on JPEGs losslessly, with specialized software which manipulates the compressed data directly. The image remains the same in size and decodes to the exact same pixels, but in different orientation. Limited scaling and cropping is possible too.Free tools for this arejpegtransandjpegcrop, developed byhttps://jpegclub.org/.BONUS: Lossless extraction of JPEGs (and other images) from PDF documents.This can be handy too, because the file is not scaled or re-encoded in the process. Some PDF editors like LibreOffice can save images embedded in PDF documents to individual files. Some PDF images are encoded in JPEG format and should be saved us such, others are lossless and may be saved as PNG.An alternative option on Linux is thepdfimagescommand line tool.

author: thm_w
author_rank: Super Contributor
timestamp: August 31, 2022, 08:41:18 pm
content: I guess this explains why saving some images the correct rotation is lost as its a tag.It looks like in windows the built in rotate image is lossless:https://photo.stackexchange.com/questions/12361/are-windows-photo-viewer-rotations-lossless

author: Peabody
author_rank: Super Contributor
timestamp: August 31, 2022, 09:08:04 pm
content: I have the same problem with portrait mode pictures taken with my Canon T2i DSLR. They are saved by the camera in landscape mode on the SD card, and I have found that various apps may or may not correct the orientation. So I point JPEG Lossless Rotator (for Windows) to the folder, and it automatically re-writes those pictures into actual portrait mode format, without bothering those actually taken in landscape mode in the first place. And it doesn't change anything else, like the date/time values. I'm told there is a menu entry in the camera that fixes this problem, but I think that applies only if you use Canon's software to bring in the pictures. Not sure about that.

author: magic
author_rank: Super Contributor
timestamp: August 31, 2022, 09:23:09 pm
content: Quote from: thm_w on August 31, 2022, 08:41:18 pmInteresting, I would have expected such a program to be EXIF-based but it seems to actually edit the data, so it's another viable option to prepare forum images.And yes, the losless trick only works on images of dimensions that are multiples of 8 or 16 pixels, I forgot about it. But JPEGclub tools should be able to crop out the incomplete blocks at the right and bottom edge (if you are OK with losing them) and then the image can be rotated losslessly.