Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Square orientation user avatar generation for CP header #5731

Merged
merged 7 commits into from
Apr 14, 2022

Conversation

ncla
Copy link
Contributor

@ncla ncla commented Apr 3, 2022

Fixes #5729

This one takes different approach from #5730, here I forcefully generate 1:1 aspect ratio image with existing ThumbnailController@show route.

However I had to change ThumbnailController to allow to override orientation, because before it would read the orientation from the asset, and it would be impossible to force cp_thumbnail_small_square image manipulation preset.

The only other place where this thumbnail route seems to be used is in src/Assets/Asset.php. The orientation path segment is optional and should not break existing usage.

One concern I see is that the avatar() method on HasAvatar trait could impact the avatar outputted on Antlers front-end, but from what I can see it does not (I tried outputting avatar from {{ current_user }}. From my understanding Statamic/Auth/User is used for CP user only? It would be amusing to receive an URL from CP thumbnail route.

I am okay if this PR does not get merged, while this is neater solution than #5730, it is slightly more complex and riskier (maybe it breaks something I am not aware of). But if you think this is good approach, then let me know if this needs additional adjustments, more than happy to address them. Regardless this was a journey for me to deep dive Statamic CMS source code a bit.

@ncla
Copy link
Contributor Author

ncla commented Apr 3, 2022

Oops, completely forgot about the tests. Hold on.. 😅

@jasonvarga
Copy link
Member

One concern I see is that the avatar() method on HasAvatar trait could impact the avatar outputted on Antlers front-end, but from what I can see it does not

You're right. It's different on the frontend. avatar when used on the frontend would have different logic. You'd get the actual asset object, not the thumbnail URL used in the cp.

{{ current_user }}
  {{ avatar /}} => /assets/myavatar.jpg

  {{ avatar }}
    {{ filename }} => myavatar
    etc
  {{ /avatar }}
{{ /current_user }}

Nice PR!

@jasonvarga jasonvarga merged commit e60d423 into statamic:3.3 Apr 14, 2022
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.

User avatar in control panel header does not cover whole circle if avatar image aspect ratio is not 1:1
2 participants