Image processing rotates images

I’m facing an issue with image processing that has been causing unexpected image rotation.

I use the following code to process and display images:

{{ range .Params.images }}
  {{ with resources.Get .image}}
    {{ with .Resize "620x webp" }}
      <img src="{{ .RelPermalink }}" alt="">
    {{ end }}
  {{ end }} 
{{ end }}

The processed images are rotated horizontally, even though the original images have the correct orientation in their EXIF data.

The short story is that Hugo’s image handling does not respect the EXIF rotation info. I have had it on my todo list to improve on for some time, and we’ll get there.

There are workarounds described here on the forum (which involves reading the exif info and rotate the image), but for my Hugo use cases, I seem to always have some kind of processing step (publish from LightRoom) and this has never been an issue for me. But I do understand the problem, and I will fix it (probably when I get around to upgrading the EXIF library we use).

1 Like

Thanks, I’ll look into some of the workarounds. This is for a client’s website so manually processing the images is not a real option for me.

1 Like

+1 :slight_smile:

Hello! I had the exact same issue and choose to re-process the images to solve my problem, although all the answers previously mentioned in this fourum are totally correct I made a few very helpful discoveries along the way that may help people in the future:

  1. You can predict this issue for looking for the Orientation EXIF tag using the command line EXIF tool. My problematic images all had the value of Left-bottom, good images had no value.
  2. Basically all good photo processing software refuses to add this EXIF data. This problem was root caused when I tried using Apple’s built-in export feature in their Photos app. RawTherapee, Lightroom CC, Lightroom Classic and GIMP’s default settings all prevent this.
  3. It can be easily fixed using any of the mentioned tools above or using something like image-magik, writing a script to run exif then rotate based on the value then remove the tag is trivial. I just threw them all back in Lightroom and cooked them again :person_shrugging:.

The next release (v0.121.2) includes an AutoOrient image filter that rotates and flips as needed per the EXIF orientation tag.

5 Likes