As it states in the image package’s documentation (image package - image - Go Packages), you have to register the formats that you want to use first:
Decoding any particular image format requires the prior registration of a decoder function. Registration is typically automatic as a side effect of initializing that format’s package so that, to decode a PNG image, it suffices to have
import _ “image/png”
in a program’s main package. The _ means to import a package purely for its initialization side effects.
If you are unsure what decode function to use when you want to decode an image, just use something like filepath.Ext to first check the extension type and if you’re going to be working with multiple image formats, you can simply register all of the formats with the underscore importing.