Skip to content

feat: use images.AutoOrient in helper/image#1294

Merged
CaiJimmy merged 4 commits into
masterfrom
1292-responsive-image-variants-ignore-exif-orientation-portrait-images-rotated
Mar 5, 2026
Merged

feat: use images.AutoOrient in helper/image#1294
CaiJimmy merged 4 commits into
masterfrom
1292-responsive-image-variants-ignore-exif-orientation-portrait-images-rotated

Conversation

@CaiJimmy
Copy link
Copy Markdown
Owner

@CaiJimmy CaiJimmy commented Mar 5, 2026

Configurable via .Site.Params.imageProcessing.autoOrient

Disabled by default, because it will generate a new version of image regardless if the image has changed orientation.

closes #1292

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Mar 5, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.AutoOrient via images.Filter to $resource prior to returning it from layouts/_partials/helper/image.html.
  • Replace with $resource block with an explicit if $resource guard.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread layouts/_partials/helper/image.html Outdated
Comment on lines +36 to +37
{{ $filter := images.AutoOrient }}
{{ $resource = $resource | images.Filter $filter }}
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
{{ $filter := images.AutoOrient }}
{{ $resource = $resource | images.Filter $filter }}
{{ if reflect.IsImageResourceProcessable $resource }}
{{ $filter := images.AutoOrient }}
{{ $resource = $resource | images.Filter $filter }}
{{ end }}

Copilot uses AI. Check for mistakes.
Comment thread layouts/_partials/helper/image.html Outdated
Comment on lines 36 to 40
{{ $filter := images.AutoOrient }}
{{ $resource = $resource | images.Filter $filter }}
{{ if reflect.IsImageResourceWithMeta $resource }}
{{ $result = dict
"Resource" $resource
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
@CaiJimmy CaiJimmy requested a review from Copilot March 5, 2026 16:47
@CaiJimmy CaiJimmy changed the title feat: use images.AutoOrient in helper/image feat: use images.AutoOrient in helper/image Mar 5, 2026
@CaiJimmy CaiJimmy merged commit 628bb9a into master Mar 5, 2026
1 check passed
@CaiJimmy CaiJimmy deleted the 1292-responsive-image-variants-ignore-exif-orientation-portrait-images-rotated branch March 5, 2026 16:58
powerfullz pushed a commit to powerfullz/hugo-theme-stack-upstream that referenced this pull request Mar 10, 2026
* 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
@CaiJimmy CaiJimmy review requested due to automatic review settings March 23, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Responsive image variants ignore EXIF orientation (portrait images rotated)

2 participants