Hello.
Can’t seem to find a solution anywhere, and my syntax knowledge is still growing…
I’d like to process an image. I have some .png that are transparent, and Hugo doesn’t want to give it a background as it preserves that. So, I thought I’d change the image to a jpg which doesn’t have an alpha channel. However, I’m not sure how to change just the bgcolor or the format. Seems as if the image processor wants to do that secondarily to another function, like .Resize
I’m ok with that, but I don’t want to change the dimensions of the image. I can’t figure out how to combine a var with string that .Resize is looking for.
# shortcodes/img.html
{{ $src := .Page.Resources.GetMatch (printf "*%s*" (.Get "src")
# will resize to 600px wide, convert to jpg with a white background
{{$src.Resize "600w jpg #ffffff" }}
# would like to keep image size the same
{{ $srcOrigW := $src.Width }} # this does give the width
{{ $src.Resize "$srcOrigW jpg #ffffff" }} # throws error
## <$src.Resize>: error calling Resize: must provide Width or Height
I also tried: {{ $src.Resize (printf "%s%s" $srcOrigW " jpg #fff") }}
to no avail. Tried various combos of that as well.