From 86cd1838ff81e7942db772fe98a034abab7c45b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 30 Dec 2025 18:05:13 +0100 Subject: [PATCH] tpl/reflect: Make the IsImageResource implementation less technical And closer to the documentation. The old one was correct, but a bit too tied to the internal implementation. --- resources/images/config.go | 5 +++-- resources/transform.go | 14 +++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/resources/images/config.go b/resources/images/config.go index 788d9c7b6..08c0a5007 100644 --- a/resources/images/config.go +++ b/resources/images/config.go @@ -58,7 +58,8 @@ var ( ".webp": WEBP, } - imageFormatsBySubType = map[string]Format{ + // These are the image types we can process. + processableImageSubTypes = map[string]Format{ media.Builtin.JPEGType.SubType: JPEG, media.Builtin.PNGType.SubType: PNG, media.Builtin.TIFFType.SubType: TIFF, @@ -123,7 +124,7 @@ func ImageFormatFromExt(ext string) (Format, bool) { } func ImageFormatFromMediaSubType(sub string) (Format, bool) { - f, found := imageFormatsBySubType[sub] + f, found := processableImageSubTypes[sub] return f, found } diff --git a/resources/transform.go b/resources/transform.go index e404ac0d4..bb1f57fd3 100644 --- a/resources/transform.go +++ b/resources/transform.go @@ -402,12 +402,16 @@ func (r *resourceAdapter) getImageOps() images.ImageResourceOps { // IsImage reports whether the given resource is an image that can be processed. func IsImage(v any) bool { - r, ok := v.(*resourceAdapter) - if ok { - _, ok := r.target.(images.ImageResourceOps) - return ok + r, ok := v.(resource.Resource) + if !ok { + return false } - return false + mt := r.MediaType() + if mt.MainType != "image" { + return false + } + _, isImage := images.ImageFormatFromMediaSubType(mt.SubType) + return isImage } func (r *resourceAdapter) publish() { -- 2.39.5