EXIF Autorotate in Drupal

Most photographs nowadays come with some EXIF data, among which an orientation parameter that specifies how the image ought to be rotated to display properly. A lot of websites, browsers and otherwise photo uploading and viewing software support EXIF, but unfortunately Drupal 7 doesn’t in core. So if you upload an image that ought to be rotated and put it through some manipulation like resizing with Image Styles, it will most likely be lying on its side.

The ImageCache Actions module provides among other effects a filter to automatically rotate images from Image Styles based on EXIF data. It requires that the php exif extension is loaded - you can check this with php -m | grep exif, in cPanel or similar on shared hosting.
Additionally it requires an image toolkit and as far as defaults go, GD is most likely to be the one present and chosen. You can check this under Configuration —> (MEDIA) Image Toolkit. The problem with GD is that it requires a lot of memory to rotate a larger image, and you can’t resize first because width and height will be switched. On shared hosting it’s almost inevitable you’ll run into exceeded memory even as an only user attempting to rotate just one regular photo.

The solution to this is to go with ImageMagick instead. You’ll need to have the processing library installed on your server, for shared hosting that would be beyond your access and the hosting company needs to have done it/agree to do it. If installing yourself, you’ll also need to link it to php (most likely using pecl). In the shell you can check for ImageMagic with some of the following: which convert, convert -version, /usr/bin/convert -version, /usr/local/bin/convert -version. Or you can this php file on your server. If ImageMagick is there, install and enable the Drupal ImageMagick module.

Lastly, go to Configuration —> (MEDIA) Image Toolkit and select ImageMagic instead of GD. If Drupal is unable to determine the path to ImageMagick, you can give it directly from the output generated while checking whether it’s installed. Even larger images should now be rotating without a problem.