[SOLVED] How to limit imageConfig to local images?

In my theme I’m using Hugo 0.19’s imageConfig function to embed image height and width in each post’s JSON LD metadata, but this fails when the user specifies a non-local image in their post’s front matter, ie an absolute URL with protocol and everything. How can I limit this so it only calls imageConfig on local files?

Here is how I’m getting the image information, using a technique that I saw somewhere here on the forum:

   "image": {
     "@type": "ImageObject",
     "url": "{{ . | absURL }}",
     {{ with (imageConfig (printf "/static/%s" .)) }}
     "height": "{{ .Height }}",
     "width": "{{ .Width }}"
     {{ end }}

Here’s what I came up with, only attempt to get imageInfo if the image parameter from front matter doesn’t have a protocol prefix like http:// or https://:

  "image": {
    "@type": "ImageObject",
    "url": "{{ . | absURL }}"
    {{- /* Don't try to get imageConfig if image param is not local */ -}}
    {{- if not (or (hasPrefix . "http://") (hasPrefix . "https://")) -}}
    {{- with (imageConfig (printf "/static/%s" .)) -}}
    ,
    "height": "{{ .Height }}",
    "width": "{{ .Width }}"
    {{ end }}
    {{ end }}

It works. Is it hacky?