TAONAW - Emacs and Org Mode: Correcting photo orientation for org-mode in Linux

Wait 5 sec.

Here’s a niche problem: When viewing iPhone-captured photos in org-mode on Linux, they always appear in landscape orientation, even if you took them in portrait.The reason is that the sensor of the camera on the phone is physically embedded in landscape mode, so all photos are in landscape mode; when you hold the phone in portrait mode (which is how you hold it most of the time), the phone detects that and implements a fix in the EXIF data file. Essentially, a software fix to a hardware design issue.Since most photos I take are usually in portrait orientation, it means I need to twist my neck and view images at a 90-degree angle when I look at my Journelly entries.The source of the problem seems to stem from how org-mode interprets EXIF data in the photo: it doesn’t. It relies on other parts of Emacs, which in turn rely on parts of the OS, to do the job. On Linux (at least on Kubuntu, which is what I use these days), those parts don’t handle EXIF orientation information. Why and how, I am not sure, it’s more digging than I have the time for right now… but anyway - there’s a simple fix.Auto-orient, which is part of ImageMagick’s mogrify tool. And if you use Emacs on Linux, good chance it’s already installed:This operator reads and resets the EXIF image profile setting ‘Orientation’ and then performs the appropriate 90 degree rotation on the image to orient the image, for correct viewing.To execute on an image file: mogrify -auto-orient .And because I use Emacs, of course there’s a dwim-shell-command solution: (defun jtr/dwim-image-auto-orient () "Auto-orient images based on EXIF data using mogrify." (interactive) (dwim-shell-command-on-marked-files "Auto-orient images" "mogrify -auto-orient ''" :utils "mogrify" :silent-success t))That last part,:silent-success, closes the empty buffer that pops up after successful execution, as mogrify doesn’t really produce an output window. So, it will just bring us back to Dired.