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.
This commit is contained in:
Bjørn Erik Pedersen
2025-12-30 18:05:13 +01:00
parent 871da3370a
commit 86cd1838ff
2 changed files with 12 additions and 7 deletions
+3 -2
View File
@@ -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
}
+9 -5
View File
@@ -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() {