feat: use images.AutoOrient in helper/image#1294
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
hugo-theme-stack | 071240a | Commit Preview URL | Mar 05 2026, 04:58 PM |
There was a problem hiding this comment.
Pull request overview
Updates the helper/image partial to auto-orient image resources (using Hugo’s images.AutoOrient) before downstream responsive/thumbnail transformations, addressing issue #1292 where derived variants ignore EXIF orientation.
Changes:
- Apply
images.AutoOrientviaimages.Filterto$resourceprior to returning it fromlayouts/_partials/helper/image.html. - Replace
with $resourceblock with an explicitif $resourceguard.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| {{ $filter := images.AutoOrient }} | ||
| {{ $resource = $resource | images.Filter $filter }} |
There was a problem hiding this comment.
images.Filter/images.AutoOrient is applied whenever $resource is non-empty, but $resource can be a non-image page resource (or otherwise non-processable). In that case Hugo will error when filtering. Gate the auto-orient step behind reflect.IsImageResourceProcessable $resource (or use try around the filter) so non-image resources still pass through safely like before.
| {{ $filter := images.AutoOrient }} | |
| {{ $resource = $resource | images.Filter $filter }} | |
| {{ if reflect.IsImageResourceProcessable $resource }} | |
| {{ $filter := images.AutoOrient }} | |
| {{ $resource = $resource | images.Filter $filter }} | |
| {{ end }} |
| {{ $filter := images.AutoOrient }} | ||
| {{ $resource = $resource | images.Filter $filter }} | ||
| {{ if reflect.IsImageResourceWithMeta $resource }} | ||
| {{ $result = dict | ||
| "Resource" $resource |
There was a problem hiding this comment.
After filtering, $resource becomes a derived image with its own .RelPermalink/dimensions, but the returned Permalink still comes from the pre-filter resource (set earlier). This can make src/the largest srcset entry point at the unfiltered original while Width/Height come from the filtered resource, leading to inconsistent markup. Consider updating Permalink to $resource.RelPermalink after the auto-orient step (at least for local resources where $permalink was derived from the resource).
helper/imageimages.AutoOrient in helper/image
…parameter in site configuration
* feat: use images.AutoOrient in `helper/image` closes CaiJimmy#1292 * fix: check if IsImageResourceProcessable before using filter * remove local field * feat: add configurable image auto-orientation via a new `autoOrient` parameter in site configuration
Configurable via
.Site.Params.imageProcessing.autoOrientDisabled by default, because it will generate a new version of image regardless if the image has changed orientation.
closes #1292