Could be something as simple as:
file_path="${1}" mime="$(file --mime-type --brief "${file_path}")" ext="${mime#image/}" mv "${file_path}" "${file_path%.*}.${ext}"
Could be something as simple as:
That does no checks (e.g. is the file an image) and may not work on something on something like a video, but it’ll do for common image types such as png, jpeg, webp, heic, gif…