Params Width instead static number in $resource.Resize

Let’s say that I want to resize a processed image

{{ $image.Resize "600x q50" }}

Instead of specifying it in the above command I want to get it from parameters from post .Params.Width


{{ $image.Resize "(.Params.Width)x q50" }}

or 2nd scenario,
I want to I want to convert to WebP

{{ $image.Resize "600x webp drawing" }}

But want to get this 600 value from $image.Width


{{ $image.Resize "($image.Width)x webp" }}

Is that something that can be done? dynamic parameters in image processing?

{{ $variable := printf "%sx webp" $image.Width }}
{{ $image.Resize $variable }}

Something like this. You need to “printf” that string before you use it. Inside of these commands it’s not parsed.

My answer is about dynamic parameters. Using basically the same width that the image already has… not sure why you would want that. But this is usable if you for instance define width via site or article params.


Thanks. Will have a try.

@davidsneighbour is right, just wanted to point out the powers of the printf func and it’s many formatting verbs:


Thanks. Will have something to work on, on my next project.