Is it possible to use imageConfig with Pipes Resources?

I’ve been looking over the documentation for Image Processing and Page Resources, but haven’t quite understood how Pipes Resources (ie resources.Get vs .resources.Get) are related.

Basically I have some site-wide image assets I want to be able to get the height and width for in a template; these images are not in a page bundle, but are instead in the assets directory, but trying to pass Resource.Permalink to imageConfig fails utterly.

How exactly should site-global images be handled? I’d like to be able to have my theme calculate these values for the theme user, rather than have them hard code them into their config.toml, but I’ve not been able to figure out how to get an absolute path from the Resource that will reflect its position in SITE/assets vs SITE/themes/THEME/assets though resource.Get "image.png" seems to treat them as a union file system.

Nevermind, turns out – though it’s not obviously documented anywhere – that there’s imageConfig data already available on a given Resource if it’s an image.

{{ $image = resources.Get "png/image.png" }}
{{ $image.Width }}

So I’ve got what I need!

1 Like

Please document.

I’d love to, but I’m still sussing out the limits of it. For instance a resource that is piped through resources.Fingerprint seems to lose its imageConfig data. Because of that I’m not entirely confident this is a stable feature.

On the good side all the image processing tools work as well, at least to the initial Resource.

Same is true of {{ ( slice %myimage | resources.Concat "new.png" ).Width }}, which was the only way I could figure out to rename a resource.

Obviously concatenating a single image isn’t a great way to achieve a rename and a resources.Rename that maintained Image data would be preferable, but I’ve got a hard constraint of needing to make multiple size copies of the same image with dimensions in the resulting URL.

Your last example will give a “slice of resources”, which will not have any “image Width” method (which width should you pick if you have more than one?)

It doesn’t appear to give me back a slice of resources, but instead a single resources.CommonResource. However I agree that it doesn’t make much sense for resources.Concat to try and maintain Image data, it just seems to be the only available means of effecting a rename of a resource, ie:

{{ $old := resources.Get "old.png" }}
{{ $new := slice $old | resources.Concat "new.png" }}
{{ printf "%s => %s" $old.Permalink $new.Permalink }}

I would certainly prefer another means of effecting a rename when doing a Fill resize, I just haven’t found one. The automatically generated name produced by the image processing operations isn’t suitable to my needs.