-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Add $image.Process #11485
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
Add $image.Process #11485
Conversation
/cc @jmooring what do you think about this? This is something I have been wanting for a while ... It's low on tests/docs, but it's rather simple, so I would expect it to just work. |
a5d52c9
to
e6fdcd4
Compare
I like it. |
Yea, my first take on this was a little bit rushed, I will fix. |
Somewhat related ( |
e6fdcd4
to
08d99a7
Compare
@jmooring thanks for that reminder, I totally forgot about that one. Looking at that, and with the new {{ $filters := slice (images.GaussianBlur 6) (images.Pixelate 8) (images.Process "webp") }}
{{ $img = $img | $img.Filter $filters }} In the above, it should be relatively clear that the resulting image will be encoded to There's potential ambiguity here, e.g: {{ $filters := slice (images.GaussianBlur 6) (images.Process "jpg") (images.Pixelate 8) (images.Process "webp") }} But that's the user shooting himself in the foot and I think we could safely pick the last target format supplied by a I'll have a look and see how hard the above would be to implement. |
Which supports all the existing actions: resize, crop, fit, fill. But it also allows plain format conversions: ``` {{ $img = $img.Process "webp" }} ``` Which will be a simple re-encoding of the source image. Fixes gohugoio#11483
08d99a7
to
9e073d5
Compare
@jmooring I have pushed another version which adds a {{ $filters := slice (images.GaussianBlur 8) (images.Grayscale) (images.Process "jpg q30") }}
{{ $img1 := resources.Get "img1.png" | images.Filter $filters }}
{{ $img2 := resources.Get "img2.png" | images.Filter $filters }} This filter supports the same options as the method with the same name. |
Very nice. Before
After
I've been thinking about documentation for this... https://gohugo.io/functions/images/
https://gohugo.io/content-management/image-processing/
|
If we ignore older Hugo versions, I would make this into: 2 Methods:
And a set of filters, one of which aliases the method Process. And then |
I don't think we can do that. Current thinking...
And the other question is, do we deprecate the old way, if so, when? |
I think never, that would be too much noise. |
This allows for constructs like: ``` {{ $filters := slice (images.GaussianBlur 8) (images.Grayscale) (images.Process "jpg q30 resize 200x") }} {{ $img = $img | images.Filter $filters }} ``` Note that the `action` option in `images.Process` is optional (`resize` in the example above), so you can use the above to just set the target format, e.g.: ``` {{ $filters := slice (images.GaussianBlur 8) (images.Grayscale) (images.Process "jpg") }} {{ $img = $img | images.Filter $filters }} ``` Fixes gohugoio#8439
80db9b2
to
0307b02
Compare
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Which supports all the existing actions: resize, crop, fit, fill-
But it also allows plain format conversions:
Which will be a simple re-encoding of the source image.
Fixes #11483