There's a global setting for this: media visibility: off.
Then you can enable that per chat.
I have all chat images contained to only Whatsapp by default. Then I only enable some chats (family, friends) to expose images/videos to the phone.
Google Photos scoops those and backsup all family pictures shared to whatsapp to my Google Photos.
I'm the family's reliable source of truth when it comes to family photos.