-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
images.Text: Add option for horizontal alignment #13223
Conversation
cc35544
to
0f351a8
Compare
0f351a8
to
01c17b9
Compare
@bep Thanks for the review all your comments should be addressed now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This work fine, you just have to get the image before setting the options in order to calculate x offset...
{{ $fontPath := "https://github.com/google/fonts/raw/main/ofl/lato/Lato-Regular.ttf" }}
{{ $imagePath := "images/original.jpg" }}
{{ $text := "A kitten!" }}
{{ with try (resources.GetRemote $fontPath) }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else with .Value }}
{{ $font := . }}
{{ with resources.Get $imagePath }}
{{ $opts := dict
"color" "#fbfaf5"
"font" $font
"linespacing" 8
"size" 120
"x" (div .Width 2 | int)
"y" 50
"alignx" "center"
}}
{{ $filter := images.Text $text $opts }}
{{ with . | images.Filter $filter }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ else }}
{{ errorf "%s" "Unable to get resource %q" $imagePath }}
{{ end }}
{{ else }}
{{ errorf "Unable to get resource %q" $fontPath }}
{{ end }}
{{ end }}
Add an "alignx" option to the images.Text to control whether the value of the "x" option is the left border of the text (current behaviour), the center of each line or the right border. Fixes gohugoio#10849
Is there an easy way to re-trigger the tests myself? I fixed them. Also I opened #13232 to add the |
01c17b9
to
47ac7bd
Compare
No. There is a restriction in GitHub for first time contributors of a repository, it requires someone to Approve each PR build (which I guess makes sense, else spam bots would go bananas creating new CI builds). Once this is merged, any new PR or push to a PR branch from you will trigger a build without any ceremony. |
Please note that this is my first contribution to Hugo and also the first time I wrote something in Go. Please let me know if I missed anything and I will try my best to correct it.
Add an "alignx" option to the images.Text to control whether the value of the "x" option is the left border of the text (current behaviour), the center of each line or the right border.
Fixes #10849
Example with
"alignx" "left"
:Example with
"alignx" "center"
:Example with
"alignx" "right"
: