how can I determine which EXIF orientation a photo has? I have various photos in a directory with different orientations (portrait, landscape). I want to automatically align and adjust the size. Resizing works. I just can’t do the turning. Below a photo with my result, the shortcode itself and the shortcode call in an .md file. Can somebody help me with it?
Hugo Static Site Generator v0.62.2/extended darwin/amd64 BuildDate: unknown
It is clear to me that I can rotate the photos manually beforehand. But I don’t want that, it should be recognized and rotated automatically. The user should not worry about it and simply upload his photos to the “gallery” directory. But since I cannot see whether the photo is in portrait or landscape format, I cannot work with rotate (r90).
The following source also did not recognize which format is available:
You will have to check the value of the $photo.Exif.Tags.Orientation to determine which way the photo needs to be rotated. The link provided by @b_rad shows how the values of the .Orientation field relate to the spacial orientation of the image:
Using this, you can write a snippet that can rotate the image based on the .Oritientation value:
{{ with $photo }}
{{ $orientation = .Exif.Tags.Orientation }}
{{ if eq $orientation 1 }}
// Do nothing, image is right-side up
{{ else if (eq $orientation 8) }}
// Rotate the image 90deg CCW (.Resize "r90")
... so on
{{ end }}
{{ end }}
@bep
You were right, the EXIF data of the pictures was broken. I do not need to rotate the pictures because they are automatically displayed correctly. What an effort, but it does. Thank you for your help and for your working time that you are investing in the Hugo project.
I want to display 3 photos side by side. My content area is 1100px wide on the desktop. 1100/3 = 366px. Since I add a space for the photos, 365px is enough for a normal screen. For high-resolution Apple devices, the whole thing has to be doubled: 365px * 2 = 730px. The area around the image tag could be optimized in the code. This would deliver 365px for normal devices and 730px for high-resolution devices.
Due to the different device sizes, the respective photo must be reduced dynamically. You can do this in the .gallery-item class and there in the img tag with width: 100%; height: auto;